Eliminate duplicate rows in a result set.

Eliminates duplicate rows from the result set, forcing the database to sort or hash to find uniqueness. Often a symptom of missing JOIN conditions or imprecise filtering. Consider whether deduplication belongs in the query or the application layer.

Compatibility

Filter by Database
SQL DISTINCT Compatibility Across Databases
Database System Support Status Since Version Notes
MySQL Native all DISTINCT ON not supported
PostgreSQL Native all Supports DISTINCT ON
SQL Server Native all Standard only
Oracle Native all Standard only
SQLite Native all Standard only

Details

Remove duplicate rows.

Standard Syntax

SELECT DISTINCT column FROM tbl;

Version Support

MySQL: Native in all listed versions PostgreSQL: Native in all listed versions SQL Server: Native in all listed versions Oracle: Native in all listed versions SQLite: Native in all listed versions

Per-Database Syntax & Notes

MySQL Native syntax

DISTINCT ON not supported

SELECT DISTINCT col FROM tbl;

PostgreSQL Native syntax

Supports DISTINCT ON

SELECT DISTINCT ON (col1) col1, col2 FROM tbl;

SQL Server Native syntax

Standard only

SELECT DISTINCT col FROM tbl;

Oracle Native syntax

Standard only

SELECT DISTINCT col FROM tbl;

SQLite Native syntax

Standard only

SELECT DISTINCT col FROM tbl;