Tuesday, December 15, 2009

Use of EXCEPT operator and comparing tables

EXCEPT operator exists in SQL Server 2005 and higher. It is particularly useful when one needs to compare two tables of identical structure and to select those records from the first table that do not exist in the second one.


SELECT column1, column2, column3 FROM Table1
EXCEPT
SELECT column1, column2, column3 FROM Table2


or even


SELECT * FROM Table1
EXCEPT
SELECT * FROM Table2

No comments:

Post a Comment