日期:2014-05-18  浏览次数:20348 次

文章系统,查询所有类别下的一条最新文章,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)