SQL DISTinc 的难题

北极星6666 2008-03-21 09:44:03
Sql= "select DISTINCT (UserID),Content,Title,RootID,JoinTime from Dv_Boke_Post where Content is not null and stype=0 order by JoinTime Desc "

我只想让记录集中不要存在相同的UserID
可是我上面这样写,怎么还会影响到Content字段呢
因为Content是ntext类型
真是搞不懂啊

后来这样写报是不会报错,可记录集里面还是会有重复的UserID
Sql= "select (UserID),Content,Title,RootID,JoinTime from Dv_Boke_Post where Content is not null and stype=0 and [userid] in (select distinct [userid] from Dv_Boke_Post) order by JoinTime Desc "

请您快帮帮我啊

...全文
91 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
银狐被占用 2008-03-21
  • 打赏
  • 举报
回复
select * from Dv_Boke_Post where id in(select min(id) from Dv_Boke_Post where Content is not null and stype=0 group by userid)

ID字段必须是唯一的。
如果没有该字段,那么换成字段里唯一值就可以了。
若白师妹 2008-03-21
  • 打赏
  • 举报
回复
DISTINCT 会对你select 所有的栏位起效果

28,409

社区成员

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

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