Saturday, October 3, 2009

Comparing SQL Server INTERSECT and EXCEPT operators.

With SQL Server 2005, Microsoft introduced the INTERSECT and EXCEPT operators to further extend what you could already do with the UNION and UNION ALL operators.

INTERSECT - gives you the final result set where values in both of the tables match
EXCEPT - gives you the final result set where data exists in the first dataset and not in the second dataset
The advantage of these commands is that it allows you to get a distinct listing across all of the columns such as the UNION and UNION ALL operators do without having to do a group by or do a comparison of every single column.

Like the UNION and UNION ALL operators the table structures need to be consistent as well as the columns need to have compatible data types.

for more info visit the link INTERSECT and EXCEPT

No comments: