0

Please, help to find appropriate query.

Task: table contains sms. Select latest sms from each conversation

Table example:

enter image description here

Query result

enter image description here

Thanks a lot in advance

1
  • 1
    Adjust the sample data, have some date values in other order than id. Commented Mar 20, 2018 at 9:33

2 Answers 2

2

Here is the solution to your problem:

SELECT MAX(id) AS ID, conversationId, Max(date) AS Date FROM Table_name GROUP BY conversationId 
Sign up to request clarification or add additional context in comments.

Comments

1

Use subquery with correlation

select * from table t where date = (select max(date) from table where conversationid = t.conversationid) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.