We have 2 tables:
- vt_blast: id, user_id, content, published_time
- vt_user: id, name
- Relations: vt_blast.user_id --> vt_user.id
Task: Get lastest blast for each user (if he has)
SQL query:
select * from vt_blast where id IN (
select max(id) from
(select user_id, max(published_time) as mtime from vt_blast group by user_id) t1
inner join vt_blast on vt_blast.user_id = t1.user_id and vt_blast.published_time = t1.mtime
group by t1.user_id) order by published_time desc;
Title:
MySQL - Group by, max, unique rows?
Description:
We have 2 tables: - vt_blast: id, user_id, content, published_time - vt_user: id, name - Relations: vt_blast.user_id --> vt_user.id ...
...
Rating:
4