文章系统,查询所有类别下的一条最新文章,sql要怎么写啊?
文章表名:news
类别字段:formid
增量主键:id
news表时面存储文章,formid表示文章的类别
现在要查询最新文章,每个类别一条,sql要怎么写?
[解决办法]
select * from news as tmp
where not exists(select 1 from news where formid=tmp.formid and id> tmp.id)
发布时间: 2012-01-13 22:43:29 作者: rapoo
文章系统,查询所有类别下的一条最新文章,sql要怎么写啊?
文章表名:news
类别字段:formid
增量主键:id
news表时面存储文章,formid表示文章的类别
现在要查询最新文章,每个类别一条,sql要怎么写?
[解决办法]
select * from news as tmp
where not exists(select 1 from news where formid=tmp.formid and id> tmp.id)