DISTINCT
A keyword that removes duplicate rows from a query's answer, or duplicate values inside an aggregate such as COUNT.
In more detail
DISTINCT applies to the whole answer row, so adding a second column usually brings duplicates back. Inside COUNT it counts different values, which is how you count orders rather than order lines after a join.
Examples
SELECT DISTINCT status FROM orders;COUNT(DISTINCT customer_id)Related terms
- SELECT — The SQL statement that reads data: it names the columns you want in the answer and, with FROM, the tables they come from.
- COUNT — An aggregate that counts rows with COUNT(*), or non-NULL values with COUNT(column).
- grain — What exactly one row of a result, table or report represents, such as one order, one order line or one customer per month.
Taught in
- The SELECT Statement And Projection — PostgreSQL, Indexing & Relational Data Modeling
- Aggregate Functions — PostgreSQL, Indexing & Relational Data Modeling
- Grouping By Multiple Columns — PostgreSQL, Indexing & Relational Data Modeling