An example would be VK dialogues.

I make a request to the message database, where data is grouped by user ID.
The data is displayed old, that is, the date in the user group is the one that is assigned to the very first message sent to it.
For example, dialogue 1. June 17, 2. June 18, and so on. Deduces the one that from June 17, and you need to display new ones, after June 18.
The request itself :

SELECT * FROM chat WHERE dialog IN ($dialog_value) GROUP BY users ORDER BY date DESC

The idea is that the dialogues are brought up above the old ones and even higher ones with the status = 1 value.

The structure of the chat table :
id, dialog (general conference ID), text (Test message), users (user ID of the person who sent the message), date, status (Message delivery status).

    1 answer 1

    When grouping MySQL for columns not included in group by, it takes the first value for the group, and you need to take the maximum. And instead of '*' it may be worthwhile to select only the single column users, for the values ​​of the others cannot be used anyway because they are again the first ones that came across for the group.

     SELECT *,max(date) maxdt,max(status) maxst FROM chat WHERE dialog IN ($dialog_value) GROUP BY users ORDER BY maxst DESC, maxdt DESC