Answer the question
In order to leave comments, you need to log in
How to return a list of dialogs based on messages?
There is a table with user messages, you need to select a list of dialogs with an SQL query. In fact, you need to get 1 row with each user (user_id), sorted by date.
The screenshot shows the lines that should be in the answer.
Answer the question
In order to leave comments, you need to log in
Not the most beautiful and very difficult solution, it will slow down on large tables.
SELECT id, user_id, read_state, text, date, out
FROM Table AS T1
WHERE date = ( SELECT MAX(date) FROM Table Where user_id=T1.user_id )
SELECT T1.id, T1.user_id, T1.text, T1.date
FROM Table1 AS T1 INNER JOIN
( SELECT user_id, MAX(date) AS date FROM Table1 GROUP BY user_id) AS T2
ON T1.user_id=T2.user_id AND T1.date=T2.date
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question