问一句SQL的写法

huidan 2004-12-09 06:29:32
sql = "select DISTINCT username from book order by id desc"
这句只能取出表中的不同名字
但是我想要的是:
取出不同的名字,但也要相关的其他字段,比如ID这些

请问应该怎么写
...全文
59 点赞 收藏 11
写回复
11 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
select * from book where id in (select distinct id from book)
回复
超级大笨狼 2004-12-10
select * from book where id in (SELECT id FROM book GROUP BY id
)
回复
超级大笨狼 2004-12-10
select * from tb where id in (SELECT id FROM book GROUP BY id
)
回复
超级大笨狼 2004-12-10
SELECT id ,max(其他字段)FROM book GROUP BY id
回复
select * from book inner join [select distinct username form book] as book1 on book.username=book1.username order by id desc
回复
写错了,不好意思
回复
select * from [select distinct username form book] order by id desc
回复
kseawolfk 2004-12-09
我问个问题,要是有很多字段怎么办?一个个全协上去啊?那不累死?!
回复
yjb136 2004-12-09
sql = "select DISTINCT * from book order by id desc"

这样不对
sql = "select DISTINCT username,id from book order by id desc"
这才对呀

DISTINCT 这一个只能去限定username

如果每个字段都限定那成什么样了
回复
myboll 2004-12-09
sql = "select DISTINCT * from book order by id desc"
回复
sql = "select DISTINCT username,id from book order by id desc"
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

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