3. Statements : OpenROAD SQL Statements : Select Statement : Union Clause
 
Share this page                  
Union Clause
The union clause combines the results of a number of select statements. The general syntax is:
subselect
union subselect {union subselect}
You can enclose a subselect in parentheses to make it easier to read unioned select statements.
OpenROAD uses the column names in the first subselect's column list to build the correspondence to the frame variables. Consequently, in the column list for the second and subsequent selects, you cannot use the following formats:
:var = column, ...
column as var, ...
You can join any number of subselects with the union clause. However, all the rows returned by a unioned select statement must be identical to each other in type. For example, the following select statement selects the names and numbers of people from different organizations:
select ename as name, enumber as number
from employee
union
select dname, dnumber
from directors
where dnumber <= 100;
The previous statement is valid because each subselect is returning an employee name and number. You could not union a select that returns an employee name and number with a select statement that returns, for example, an employee name and address because the two select statements are not returning columns of the same type and format.