Skip to content
Rene Saarsoo edited this page Jul 17, 2022 · 9 revisions

SQL standard defines the following set operations:

  UNION [ALL | DISTINCT]
| EXCEPT [ALL | DISTINCT]
| INTERSECT [ALL | DISTINCT]

All dialects support UNION, with rest there are variations:

BigQuery:

  UNION {ALL | DISTINCT}
| INTERSECT DISTINCT
| EXCEPT DISTINCT

DB2:

  UNION [ALL]
| EXCEPT [ALL]
| INTERSECT [ALL]

Hive:

UNION [ALL | DISTINCT]

MariaDB:

  UNION [ALL | DISTINCT]
| EXCEPT [ALL | DISTINCT]
| INTERSECT [ALL | DISTINCT]
| MINUS [ALL | DISTINCT]

MySQL:

UNION {ALL | DISTINCT}

N1QL:

  UNION [ALL]
| EXCEPT [ALL]
| INTERSECT [ALL]

PL/SQL:

  UNION [ALL]
| EXCEPT
| INTERSECT

PostgreSQL:

  UNION [ALL | DISTINCT]
| EXCEPT [ALL | DISTINCT]
| INTERSECT [ALL | DISTINCT]

Redshift:

  UNION [ ALL ]
| INTERSECT
| EXCEPT
| MINUS

Spark:

  UNION [ALL | DISTINCT]
| EXCEPT [ALL | DISTINCT]
| INTERSECT [ALL | DISTINCT]

SQLite:

  UNION [ALL]
| EXCEPT
| INTERSECT

Transact-SQL:

  UNION [ALL]
| EXCEPT
| INTERSECT

Trino:

  UNION [ALL | DISTINCT]
| EXCEPT [ALL | DISTINCT]
| INTERSECT [ALL | DISTINCT]
Clone this wiki locally