The following commands can be used to combine multiple queries.

UNION / UNION ALL

The UNION command is used to combine two queries.

Syntax


selectQuery UNION [ALL] selectQuery2;

Arguments

  • selectQuery / selectQuery2: Any valid SELECT query.

  • UNION [ ALL ]: The UNION keyword combines the two data sets from selectQuery and selectQuery2. When the ALL keyword is included, all rows are included, even when they are duplicates across the tables. Otherwise, duplicates are omitted.

Examples

SELECT id, firstName, lastName FROM users UNION SELECT id, firstName, lastName FROM users_archive2011;