Thursday, April 8, 2010

UNION/INTERSECT CLAUSES

0 comments
1. Union Clause
The UNION clause combines the results from two or more SQL SELECT statements into a single result set containing rows from all the queries in the UNION operation

By default, UNION eliminates duplicate rows from the combined result set.

select count(*) as total applications
from Employee_Application

union

select count(*) as total_applciations
from Loan_Applications

2.Intersect Clause

The following query returns any distinct values that are returned by both the query on the left and right sides of the INTERSECT operand.

SELECT ProductID FROM Production.Product
INTERSECT
SELECT ProductID FROM Production.WorkOrder

3. Except Clause
SELECT ProductID FROM Production.Product
EXCEPT
SELECT ProductID FROM Production.WorkOrder

0 comments: