Last week, I was in an assignment and one of the guys asked this question: “How to Return non matching records from two tables?”
So, here goes the scenario. There are two tables, say, Table1 & Table2 and both of them have a column, say col1. And you want to return records that are unique to each table (non-matching) based on col1.
So, you need to write a query that returns CCC & ZZZ.
Here is the solution:
( select col1 from table1 t1 EXCEPT Select col1 from table2 t2 ) UNION ( select col1 from table2 t2 EXCEPT Select col1 from table1 t1 )
There are other techniques too to solve the above problem. Do post comments and let the readers know about your solution.