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

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

我只想输出不重复的内容,如何实现?
只输出:
1145
1127
1131
...全文
165 18 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
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

28,409

社区成员

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

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