SQL语句重复的只显示一条

[复制链接]
查看11 | 回复5 | 2009-3-23 09:18:35 | 显示全部楼层 |阅读模式
Rs.Open "select * from userpc order by id desc",conn,1,1
字段 username 有重复内容 如何让它只显示一条
一个一个试了都不行,会卡死。全部代码(usenpc表下有id loginName tel LinkMan这几个字段,把username改成tel,就是让tel 有重复的只显示一条):

回复

使用道具 举报

千问 | 2009-3-23 09:18:35 | 显示全部楼层
select username,max(col1) col1,max(col2) col2 from userpc group by username order by id desc col1和col2都是你表中的字段名,因为不确定你有几个字段,所以如果有其他字段你自己补充...
回复

使用道具 举报

千问 | 2009-3-23 09:18:35 | 显示全部楼层
Rs.Open "select distinct * from userpc order by id desc",conn,1,1除非你只选择这个字段Rs.Open "select distinct usernamefrom userpc order by id desc",conn,1,1...
回复

使用道具 举报

千问 | 2009-3-23 09:18:35 | 显示全部楼层
如果有2个id,那么不可能显示一条的。...
回复

使用道具 举报

千问 | 2009-3-23 09:18:35 | 显示全部楼层
Open "select distinct(username) * from userpc order by id desc",conn,1,1...
回复

使用道具 举报

千问 | 2009-3-23 09:18:35 | 显示全部楼层
select distinct(username),id from userpc...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行