我现在有一个文章表 有两个字段 id 和 catid
我想给 每个catid 有8个分类 列出 最新发的一篇文章
select * from post gruop by catid order by id desc;
这样我只能取出 8条 id 最小的 也就是 最老的一篇文章 order by id 并不起作用
如何才能按照id号desc开始排序
阿神2017-04-17 16:54:09
Your select * is originally not a rigorous way of writing, but MySQL has strong compatibility and defaults to the smallest one. If SQL has group by, then the select can only contain columns in group by or aggregation functions , you commented that order by cannot be done because you need to add an alias to the column after max.
select max(id) id, catid from post group by catid order by id desc;