justcode.ikeepstudying.com
Mysql:通过group by 获取最新一条信息, Get Last Record In Each MySQL Group - Just Code
假设我们有一张表: id category_id post_title ------------------------- 1 1 Title 1 2 1 Title 2 3 1 Title 3 4 2 Title 4 5 2 Title 5 6 3 Title 6 我想要category_id只取一条最新的: select * from posts group by category_id 或者: select * from posts group by category_id order by id desc 但是上面的语句得到的结果是: id category_id post_title …