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
distinct() function (not select qualifier) in postgres

I just came across a SQL query, specifically against a Postgres database, that uses a function named "distinct". Namely: select …

sql postgresql distinct distinct-on
Multiple DISTINCT ON clauses in PostgreSQL

Is it possible to select rows that are DISTINCT ON some separate, independent sets of columns? Suppose I want all …

sql postgresql duplicates distinct-on
How to order distinct tuples in a PostgreSQL query

I'm trying to submit a query in Postgres that only returns distinct tuples. In my sample query, I do not …

sql postgresql distinct-on
How to use "distinct on" with doctrine?

I try to use "distinct on" with doctrine but I get the following error: Error: Expected known function, got 'on' …

php symfony doctrine-orm distinct distinct-on