asp禁止输出数据库中重复的内容?急!

wwwyi13cn 2008-04-02 05:07:55
比如数据库"okid"表中有:
1145
1127
1145
1145
1127
1127
1131
1131

我只想输出不重复的内容,如何实现?
只输出:
1145
1127
1131
...全文
121 点赞 收藏 18
写回复
18 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
wwwyi13cn 2008-04-02
回上楼
sql="select top 200 okid from Posts where UserName='"& UserName &"' and IsTopic=0 group by okid order by max(id) Desc"


经测式,非常正确,
回复
sql="select top 200 okid from Posts where UserName='"& UserName &"' and IsTopic=0 group by okid order by max(id) Desc"
这个运行正确????
邪门

sql="select top 200 * from Posts where UserName='"& UserName &"' and IsTopic=0 group by okid order by id Desc"

这样的正确还差不多
回复
wwwyi13cn 2008-04-02
15楼gingerkang正确
100分是你的了。
回复
gingerkang 2008-04-02
sql="select top 200 okid from Posts where UserName='"& UserName &"' and IsTopic=0 group by okid order by max(id) Desc"
回复
要是用DISTINCT的话
你得这样select addtime,distinct okid from table ORDER BY addtime desc

使用group by 的话,直接可以

select * from 你的表名 group by okid ORDER BY addtime desc
回复
wwwyi13cn 2008-04-02
引用8楼这句正确

sql="select top 200 okid from Posts where UserName='"& UserName &"' and IsTopic=0 group by okid"


但是加上order by id Desc
错误
sql="select top 200 okid from Posts where UserName='"& UserName &"' and IsTopic=0 group by okid order by id Desc"

错误类型:
Microsoft JET Database Engine (0x80040E21)
试图执行的查询中不包含作为合计函数一部分的特定表达式 'id'
回复
建议使用select * from 你的表名 group by okid
回复
gingerkang 2008-04-02
一个okid可能对应多个id,按它排序在逻辑上也说不通
回复
wwwyi13cn 2008-04-02
回7楼:

错误类型:
Microsoft JET Database Engine (0x80004005)
ORDER BY 子句与 (id) DISTINCT 冲突。
回复
wwwyi13cn 2008-04-02
错误类型:
Microsoft JET Database Engine (0x80004005)
ORDER BY 子句与 (id) DISTINCT 冲突。
回复
gingerkang 2008-04-02
sql="select top 200 * from Posts where UserName='"&UserName&"' and IsTopic=0 order by id Desc"
==>
sql="select distinct top 200 okid from Posts where UserName='"& UserName &"' and IsTopic=0"
or
sql="select top 200 okid from Posts where UserName='"& UserName &"' and IsTopic=0 group by okid"
回复
hookee 2008-04-02
<%
sql = "select distinct top 200 okid from Posts where UserName='" & UserName & "' and IsTopic=0 order by id Desc"
Rs.Open sql,Conn,1,1
Do While Not RS.EOF
okid = Rs("okid")
Response.Write(okid)
Response.Write("<br>")
Rs.MoveNext
loop
Rs.Close
%>
回复
wwwyi13cn 2008-04-02
错误类型:
Microsoft JET Database Engine (0x80040E21)
不能将已选定 '*' 的字段中组合。
回复
siyee 2008-04-02
sql="select top 200 * from Posts where UserName='"&UserName&"' and IsTopic=0 group by okid"
Rs.Open sql,Conn,1
Do While Not RS.EOF
okid=Rs("okid")
Response.Write(okid)
Response.Write("<br>")
Rs.MoveNext
loop
Rs.Close
回复
wwwyi13cn 2008-04-02
帮改一下吧:
输出okid不重复的值

sql="select top 200 * from Posts where UserName='"&UserName&"' and IsTopic=0 order by id Desc"
Rs.Open sql,Conn,1
Do While Not RS.EOF
okid=Rs("okid")
Response.Write(okid)
Response.Write("<br>")
Rs.MoveNext
loop
Rs.Close




回复
hookee 2008-04-02
sql语句加distinct关键字
sql= "select distinct xxx from okid"
rs.open sql, conn,1,1
回复
wwwyi13cn 2008-04-02
详细点,谢谢。
回复
gingerkang 2008-04-02
你只查找不重复的出来就好了
select distinct okid from table
or
select okid from table group by okid
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

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