Top "Distinct-on" questions

Use this tag for questions relevant to DISTINCT ON, which is used to eliminate rows that match on all specified expressions.

PostgreSQL DISTINCT ON with different ORDER BY

I want to run this query: SELECT DISTINCT ON (address_id) purchases.address_id, purchases.* FROM purchases WHERE purchases.product_…

sql postgresql sql-order-by distinct-on
PostgreSQL does not allow me to group a column with order

In PostgreSQL i want to fetch every users at once and order them by date. This is my query: SELECT …

postgresql group-by distinct distinct-on
SQL: What does "DISTINCT ON (expression)" do?

I understand how DISTINCT works, but I don't understand DISTINCT ON (expression). Take the first example from this screenshot: How …

sql database postgresql mod distinct-on
PostgreSQL: Select only the first record per id based on sort order

For the following query I need to select only the first record with the lowest shape_type value (ranges from 1 …

sql postgresql distinct greatest-n-per-group distinct-on
Applying a different order to postgres "DISTINCT ON" using rails

I have a rails app: user has_many :projects user has_many :tasks, :through => :projects project has_many :tasks …

ruby-on-rails-3 activerecord sql-order-by distinct-on
Selecting rows ordered by some column and distinct on another

Related to - PostgreSQL DISTINCT ON with different ORDER BY I have table purchases (product_id, purchased_at, address_id) …

postgresql greatest-n-per-group distinct-on