Labels

Sunday, 22 May 2016

Set Operators in SQL Server

                                                 SET OPERATORS

Set operators are used to join the records of 2/more tables.

Union:

Displays unique values from both tables.In unique all selected columns need to be same datatype.

SELECT * FROM T1
UNION
SELECT * FROM T2

Intersect:

Displays similar values existing in both tables

SELECT * FROM T1
INTERSECT
SELECT * FROM T2

Except:

Displays distinct values from first table which are not present in second table.

SELECT * FROM T1
EXCEPT
SELECT * FROM T2

Union All:

It selects all values i.e including duplicate values
            
SELECT * FROM T1
UNION ALL
SELECT * FROM T2

2 comments: