Most major RDBMSs support the DISTINCT
clause, which allows us to get unique – or “distinct” – rows from our SQL queries. But PostgreSQL’s implementation of this clause has an extra option that most other RDBMSs don’t include.
PostgreSQL allows us to include the ON()
option when using DISTINCT
. This enables us to specify exactly which columns should be evaluated by the DISTINCT
modifier, while simultaneously allowing us to return columns that aren’t evaluated.