bookcontent是用来存放图书内容的一个表,其中图书内容是根据图书ID一章一章连载的,我现在想把最新每本书更新的最新章节给抓出来,使用了如下语句:SELECT * FROM `bookcontent` group by book_id order by addtime desc,
可是这样抓出来的结果并不是我想要的,这样只能抓出最早插入的图书章节记录,怎么才能抓出最后插入的记录呢
补充下,假如数据表如下:
table: bookcontent
id title book_id addtime
1 a 1 2008-2-1
2 b 1 2008-3-1
3 c 1 2008-4-1
4 a 2 2008-2-5
5 b 2 2008-3-5
6 c 2 200-4-5
如何同时只抓出
3 c 1 2008-4-1
6 c 2 200-4-5
这两条记录
试试
1、select * from bookcontent as aaa where not exists(
select * from bookcontent where book_id =aaa.book_id and addtime > a.addtime)
2、select * from bookcontent where addtime in(select max(addtime) from bookcontent goup by book_id)
2、
select * from (select * from 表 order by 最大值的那个字段 desc)
temp group by 所需分组的字段