UNION adds the result of a second SELECT clause to the table created by the main SELECT command. With the UNION clause, each SELECT must result in the same number of output columns and each column must correspond in type. The first SELECT command determines the names and the types of the output columns. Numeric variables must correspond to numeric variables, string variables with string variables.
The main SELECT command defines the table that is produced when using the UNION statement. For example, assume two tables, one for current employees and one for ex-employees. A single output table for all employees could be produced with the UNION clause:
SELECT NAME SALARY FROM EMPLOYEE ON ALLEMPLOYEES -
UNION SELECT NAME SALARY FROM EXEMPLOYEE
This creates a new table with two columns and a row per employee.
As many SELECT clauses as required may be UNIONed together as long as the rules on number and type of variables are followed.
If sequence of the output table is important, use the ORDER BY clause to specify it. Any such ORDER BY should follow the last clause of the last SELECT in the command.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.