PostgreSQL SyntaxLesson 18Free preview
PostgreSQL SELECT DISTINCT
This lesson is part of PostgreSQL · All levels
Summary
SELECT DISTINCT displays only a unique value combination so that duplicate rows do not appear on the result. DISTINCT is applicable to all selected columns at once, not per column. PostgreSQL also provides DISTINCT ON to select one row per group according to the sequence rules.
Key points
- DISTINCT eliminates duplicate rows from the query results.
- Uniqueness is judged by a combination of all the selected columns.
- DISTINCT ON (expression) selects one row per group by PostgreSQL.
- COUNT(DISTINCT column) calculates the number of unique values.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.