9.6. The UNION, INTERSECT, and EXCEPT Operators

UNION, INTERSECT, and EXCEPT are operators that can be used to obtain the union, intersection, and difference between fullselect, subselect, or values-clause. Figure 9.31 shows the syntax diagram of the UNION, INTERSECT, and EXCEPT operators.

Figure 9.31. Syntax diagram of the UNION, INTERSECT, and EXCEPT operators
>>-+-subselect---------+---------------------------------------->
   +-(fullselect)------+
   '-| values-clause |-'

   .----------------------------------------------.
   V                                              |
>----+------------------------------------------+-+------------->
     '-+-UNION---------+--+-subselect---------+-'
       +-UNION ALL-----+  +-(fullselect)------+
       +-EXCEPT--------+  '-| values-clause |-' +-EXCEPT ALL----+ +-INTERSECT-----+ ...

Get Understanding DB2®: Learning Visually with Examples now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.