As Dougman published one of the most effective ways to compare two datasets is GROUP them. I usually use this query to compare two tables:
SELECT MIN(which), COUNT(*), pk, col1, col2, col3, col4
FROM (SELECT 'old data' which, pk, col1, col2, col3, col4
FROM t
UNION ALL
SELECT 'new data' which, pk, col1, col2, col3, col4 FROM t_new)
GROUP BY pk, col1, col2, col3, col4
HAVING COUNT(*) != 2
ORDER BY pk, MIN(which);
source
share