SQL - get latest records from table where field is unique
Posted
by
89stevenharris
on Stack Overflow
See other posts from Stack Overflow
or by 89stevenharris
Published on 2012-09-19T15:36:15Z
Indexed on
2012/09/19
15:37 UTC
Read the original article
Hit count: 188
I have a table of data as follows
id status conversation_id message_id date_created
1 1 1 72 2012-01-01 00:00:00
2 2 1 87 2012-03-03 00:00:00
3 2 2 95 2012-05-05 00:00:00
I want to get all the rows from the table in date_created
DESC order, but only one row per conversation_id
. So in the case of the example data above, I would want to get the rows with id
2 and 3.
Any advice is much appreciated.
© Stack Overflow or respective owner