I want to find the newest message entry for each chat_id.
For example, for this table I need to get list of rows: with id=1c6bad12 for chat_id=ee5152ff and with id=e4485bdf for chat_id=29cc7217. (2th and 6th).
| id | chat_id | created_at | text | 
|---|---|---|---|
| 1442a8e8 | ee5152ff | 2023-01-09 12:38:44.237280 | hello1 | 
| 1c6bad12 | ee5152ff | 2023-05-09 10:39:25.260409 | hello3 | 
| 514c2db5 | 29cc7217 | 2023-02-14 09:05:20.284902 | qwerty1 | 
| c4247480 | ee5152ff | 2023-01-14 19:05:20.284902 | hello2 | 
| e4485bdf | 29cc7217 | 2023-06-14 11:05:20.284902 | qwerty2 | 
Now I have only such query:
SELECT * 
FROM message
ORDER BY created_at DESC, id DESC;
But it reruns all rows
 
     
     
     
    