Answer the question
In order to leave comments, you need to log in
Sorting users by latest entry in posts table, how to query?
Good afternoon.
There are tables
users - contains users.
messages - contains a bunch of messages, where there is createdAt
We need to get users and sort them in chronological order by messages.
How can this be done without requests? Maybe there are some specialized aggregate functions
Answer the question
In order to leave comments, you need to log in
select u.* from users as u
inner join messages as m
on u.id = m.user_id
group by u.id
order by max(m.createdAt);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question