我想选择id不同的前两条纪录来显示

hgxlucky 2004-08-05 08:25:13
我想选择id不同的前两条纪录来显示,我这样写的不行
select top 2 * from photo where id<>id order by id1 desc


ID1 id image ondate title
63 661 cdcatelogo.gif 2004-8-5 8:02:27 zzzzzzzzzz
64 661 foodjob.gif 2004-8-5 8:02:27 zzzzzzzzzz
65 661 hclzlogo.gif 2004-8-5 8:02:27 zzzzzzzzzz
66 662 cdcatelogo.gif 2004-8-5 8:08:44 dddddddddd
67 662 foodjob.gif 2004-8-5 8:08:44 dddddddddd
68 662 logo.gif 2004-8-5 8:08:44 dddddddddd

我想显示id1为68和65的纪录
...全文
135 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
pfc001 2004-08-06
  • 打赏
  • 举报
回复
select top 2 * from photo where id in(select distinct id from photo) order by id1 desc
古侠 2004-08-06
  • 打赏
  • 举报
回复
谢谢,学习了一招
hgxlucky 2004-08-06
  • 打赏
  • 举报
回复
用efei(草不含羞)的可以,但
sql="select top 2 * from photo where id in(select distinct id from photo) order by id1 desc"
这个就是不行,晕了
jervis82 2004-08-05
  • 打赏
  • 举报
回复
好像是在搞sql语句大集合哦,可惜我对此不精。路过。
efei 2004-08-05
  • 打赏
  • 举报
回复
如果楼主想取到这两条记录:
63 661 cdcatelogo.gif 2004-8-5 8:02:27 zzzzzzzzzz
66 662 cdcatelogo.gif 2004-8-5 8:08:44 dddddddddd
那么这样:
SELECT * FROM photo WHERE id1 in(SELECT TOP 2 Min(id1) FROM photo group by id)
yeno 2004-08-05
  • 打赏
  • 举报
回复
sql="select top 2 * from photo where id in(select distinct id from photo) and id <> '67' and id <>'66' order by id1 desc"
yeno 2004-08-05
  • 打赏
  • 举报
回复
楼主,你可以给ID1号为66和67的两条记录屏蔽掉嘛
sql="select top 2 * from photo where id in(select distinct id from photo) and id <> '67 and id <>'66' order by id1 desc"
hgxlucky 2004-08-05
  • 打赏
  • 举报
回复
sql="select top 2 * from photo where id in(select distinct id from photo) order by id1 desc"
显示的为id1为67和68的纪录
yeno 2004-08-05
  • 打赏
  • 举报
回复
写错了
select top 2 * from photo where id in(select distinct id from photo) order by id1 desc
yeno 2004-08-05
  • 打赏
  • 举报
回复
select top 2 * from (select distinct id from photo) order by id1 desc

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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