我有article table
我想要获取最新的3篇文章,但作者应该是唯一的。
我的表结构是:
article table
id | author_id
1 | 1
2 | 1
3 | 2
4 | 4
5 | 4
6 | 5
7 | 5
预期输出:article id => 7 ,5, 3
我试过了:
SELECT DISTINCT(user_id), id
FROM articles
ORDER BY id DESC
LIMIT 3
答案 0 :(得分:2)
答案 1 :(得分:1)
试试这个
select max(id) from article group by author_id order by id desc limit 3;
答案就像是
mysql> select max(id) from article group by author_id order by id desc limit 3;
+---------+
| max(id) |
+---------+
| 7 |
| 5 |
| 3 |
+---------+
3 rows in set (0.01 sec)