Questions tagged [distinct-on]

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

From PostgreSQL: Documentation:

DISTINCT ON eliminates rows that match on all the specified expressions.

Consider using the , if needed, in your question.

95 questions
-1
votes
1 answer

Rails ActiveRecord select distinct records ordered by timestamp

In the following table of data: I am trying to select from this table the records that are distinct based off of the columns itemable_id, itemable_type, and user_id. I also want the records sorted by last_viewed_at. In rails, I have been able to…
ryanpitts1
  • 862
  • 1
  • 16
  • 33
-1
votes
1 answer

Counting the total number of rows with SELECT DISTINCT ON without using a subquery

I have performing some queries using PostgreSQL SELECT DISTINCT ON syntax. I would like to have the query return the total number of rows alongside with every result row. Assume I have a table my_table like the following: CREATE TABLE my_table( …
Giacomo Alzetta
  • 2,431
  • 6
  • 17
-1
votes
1 answer

Which row is returned using DISTINCT ON in Postgres

When I use DISTINCT ON in PostgreSQL (distinct in django) which rows are retrieved in the group of rows with same fields?
mohammad
  • 2,232
  • 1
  • 18
  • 38
-1
votes
1 answer

Losing order rows with distinct - PostgreSQL

I'm working with SQL and i want to select result with numero_engin if exist else numero_train. So i'm using coalesce to do this. To romove the duplicate rows, i tried to use distinct. But the problem when using distinct, i lose the order of…
youssef
  • 159
  • 3
  • 13
-2
votes
1 answer

Mysql update first unique match only

I have a table with multiple occurence of a value (SKU) linked with a certain value for another column (column2). I want to update the value of column2 with the first match of SKU. Update table set column2 = test where sku = 18. I have twice the…
1 2 3 4 5 6
7