Pages

Thursday, August 7, 2008

Except in SQL Server

This is basically to return all the records from one result set where there is no matching in another table. This looks very similar to “Outer join” but join does horizontally and EXCEPT does vertically.

Let’s look at the example:

SELECT EmployeeID,Name,Salary,DOJ from Employee
EXCEPT
SELECT EmployeeID,Name,Salary,DOJ from Employee_HIST

With the above query we are fetching only the records which are in Employee but not in Employee_HIST.

No comments: