Skip to content
Daniël van Eeden edited this page Mar 13, 2024 · 6 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}
| EXCEPT DISTINCT
| INTERSECT 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 ]
| EXCEPT
| INTERSECT
| MINUS

SingleStoreDB (union, intersect, except and minus):

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

Snowflake:

  UNION [ALL]
| EXCEPT
| MINUS
| INTERSECT

Spark:

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

SQLite:

  UNION [ALL]
| EXCEPT
| INTERSECT

TiDB:

UNION [ALL | DISTINCT]

Transact-SQL:

  UNION [ALL]
| EXCEPT
| INTERSECT

Trino:

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