文章系统,查询所有类别下的一条最新文章,sql要怎么写啊?

Equn 2007-02-03 03:47:48
文章表名:news
类别字段:formid
增量主键:id

news表时面存储文章,formid表示文章的类别

现在要查询最新文章,每个类别一条,sql要怎么写?
...全文
155 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
marco08 2007-02-03
  • 打赏
  • 举报
回复
select * from news as tmp
where not exists(select 1 from news where formid=tmp.formid and id>tmp.id)

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧