Different column names

Corresponding columns in the Projection clauses for the combined queries must have compatible data types, but the columns do not need to use the same column names.

The following query selects the state column from the customer table and the corresponding code column from the state table.
Figure 1: Query
SELECT DISTINCT state FROM customer
   WHERE customer_num BETWEEN 120 AND 125
UNION
SELECT DISTINCT code FROM state
   WHERE sname MATCHES '*a';
The query returns state code abbreviations for customer numbers 120 through 125 and for states whose sname ends in a.
Figure 2: Query result
state

AK
AL
AZ
CA
DE
;
SD
VA
WV

In compound queries, the column names or display labels in the first SELECT statement are the ones that appear in the results. Thus, in the query, the column name state from the first SELECT statement is used instead of the column name code from the second.