PQL Union

PQL UNION Operator
The UNION operator is used to combine the result-set of two or more SELECT statements.

Notice that each SELECT statement within the UNION must have the same number of columns. The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order.

PQL UNION Syntax
Note: The UNION operator selects only distinct values by default. To allow duplicate values, use UNION ALL.

PQL UNION ALL Syntax
PS: The column names in the result-set of a UNION are always equal to the column names in the first SELECT statement in the UNION.

PQL UNION Example
Look at the following stables:

"Employees_SugarCubeCorner":

"Mane_6":

Now we want to list all the different ponies in Sugar Cube Corner and the Mane 6.

We use the following SELECT statement:

The result-set will look like this:

Note: This command cannot be used to list all ponies employed at Sugar Cube Corner and in the mane 6. In the example above we have two ponies with equal names, and only one of them will be listed. The UNION command selects only distinct values.

PQL UNION ALL Example
Now we want to list all ponies employed at Sugar Cube Corner and in the mane 6:

Result: