Wednesday, February 27, 2013

UNION SET Operator

The UNION operator returns all distinct rows retrieved by two component queries. The UNION operation eliminates duplicates while merging rows retrieved by either of the component queries. The following example illustrates the UNION operation:

The Syntax of UNION Operator

<Component Query>
UNION
<Component Query>

For Example:

SELECT CUST_NBR, NAME FROM CUSTOMER
WHERE REGION_ID = 5
UNION
 SELECT C.CUST_NBR, C.NAME FROM CUSTOMER C WHERE C.CUST_NBR IN (SELECT O.CUST_NBR FROM CUST_ORDER O, EMPLOYEE E
WHERE O.SALES_EMP_ID = E.EMP_ID  AND E.LNAME = 'MARTIN');

No comments:

Post a Comment