Skip to content
Daniël van Eeden edited this page Mar 13, 2024 · 5 revisions

SQL standard defines the following syntax for the start of a query:

SELECT [ALL | DISTINCT]

All dialects support that, but also quite a bit extra stuff:

BigQuery:

SELECT [ALL | DISTINCT] [AS {STRUCT | VALUE}]

DB2 & DB2i:

SELECT [ALL | DISTINCT]

Hive:

SELECT [ALL | DISTINCT]

MariaDB:

SELECT
  [ALL | DISTINCT | DISTINCTROW]
  [HIGH_PRIORITY]
  [STRAIGHT_JOIN]
  [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
  [SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]

MySQL:

SELECT
  [ALL | DISTINCT | DISTINCTROW]
  [HIGH_PRIORITY]
  [STRAIGHT_JOIN]
  [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
  [SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]

N1QL:

SELECT [hint_comment] [ALL | DISTINCT]

PL/SQL:

SELECT [hint] [ALL | DISTINCT | UNIQUE]

PostgreSQL:

SELECT [ALL | DISTINCT [ON ( expression [, ...] )]]

Redshift:

SELECT [TOP number | [ALL | DISTINCT]]

SingleStoreDB:

SELECT [ALL | DISTINCT | DISTINCTROW]

Snowflake:

SELECT [ALL | DISTINCT]

Spark:

SELECT [hints, ...] [ALL | DISTINCT]

SQLite:

SELECT [ALL | DISTINCT]

TiDB:

SELECT
  [ALL | DISTINCT | DISTINCTROW]
  [HIGH_PRIORITY]
  [STRAIGHT_JOIN]
  [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
  [SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]

Transact-SQL:

SELECT
  [ALL | DISTINCT]
  [TOP ( expression ) [PERCENT] [WITH TIES]]

Trino:

SELECT [ALL | DISTINCT]
Clone this wiki locally