Sunday 4 May 2014

SET Operators in T-SQL

Set Operators :

It is used to combine multiple results sets into one single result set.

There are 3 set operators in T-SQL
1) UNION/UNION ALL
2) EXCEPT
3) INTERSECT

UNION/UNION ALL :
----------------------------
It is used to combine two or more result sets into one single result set by with or without duplicates
(ie, UNION doesn't allow null values, but UNION ALL allows null values)

Example:
<<ResultSet>>
UNION or UNION ALL
<<ResultSet>>


 EXCEPT:
------------
It takes the data from one result set where there is no matching in another result set.

Example:
<<ResultSet>>
EXCEPT
<<ResultSet>>

 INTERSECT:
----------------
It takes the data from the result sets which are in common

Example:
<<ResultSet>>
INTERSECT
<<ResultSet>>


No comments:

Post a Comment