UNION:  Exercises

 

- Create an address list for all employees, customer contacts, and supplier contacts, sorted by name.  For this exercise, use employee's last name only.

 

- Change the previous query to use the employee's last name and first name.  (More than one way to do this.)

 

- Change one of the previous queries to include an additional column (call it Role) where each person is designated as Employee, Customer, or Supplier.

 

 

SYNTAX

 

Without duplication:

 

            SELECT statement1

            UNION

            SELECT statement2

            UNION

            ...

            SELECT statement-last

            ORDER BY column list

           

To include all rows, regardless of duplication:

 

            SELECT statement1

            UNION ALL

            ...

            SELECT statement-last

            ORDER BY column list

           

 

Other set operators (Oracle):  INTERSECT and MINUS