The UNION operator returns all the rows selected by either query. It is used when output is to combine all rows from multiple tables in the query.
It eliminates duplicate rows in the final result.
Syntax:
<Component query>
UNION
<Component query>;
key points:
It eliminates duplicate rows in the final result.
Syntax:
<Component query>
UNION
<Component query>;
key points:
- Semi colon should be placed at the end of the last component query.
- NULL values are considered during duplicate check.
- Output is sorted in ascending order according to the first column of SELECT clause.
- The IN operator has a higher precedence than the UNION operator.
SELECT job FROM emp WHERE deptno = 10
UNION
SELECT job FROM emp WHERE deptno = 20;
-- The above query displays the distinct jobs of employees working in 10th and 20th department.
No comments:
Post a Comment
Do you want to comment