我想选择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的纪录
...全文
89 点赞 收藏 10
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2004-08-05 08:25
社区公告
暂无公告