📍 LINK in the comments
In CTE o insert your old query
In CTE n: insert your new query
In Difference CTE:
The first part selects all records that are present in n but not in o. It uses the EXCEPT DISTINCT clause, which removes duplicate rows.
The second part does the opposite
The UNION ALL operator combines the results
In the end we are selecting everything from dif, ordering by needed columns
This query is useful for comparing the outputs of before and after query change