一个SQL语句,错在哪里?

爱着有你 2008-09-10 10:35:03
select distinct(a.objid),a.*,u.username as objusername from usr_action_other a,usr_user u where a.type=1 and a.objid=u.userid and a.username='%s' order by a.crtime desc limit %d,%d

这个SQL语句,查询的结果不具有唯一性。请问是哪里有问题?
...全文
50 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
爱着有你 2008-09-10
  • 打赏
  • 举报
回复
搞定了。
是少了group by
不过不是谢谢二楼的兄弟。
huaguocsdn 2008-09-10
  • 打赏
  • 举报
回复
你 的a.*中已经有一个a.objid了,你distinct(a.objid)得到的列名也是a.objid,重复了;
这样 select distinct(a.objid) as a_objid,a.*..........
爱着有你 2008-09-10
  • 打赏
  • 举报
回复
先谢谢二楼。
不过不好意思噢。你的没有解决我的问题呀
a.objid对应u.userid是对的,但a.username不对应u.username
因为a.userid和a.username是发起动作的用户,而a.objid才是对应接收动作的用户。

上面的语句我把a.* 去掉了以后就好了,但一加上去就不对了。不知道是为什么。
xiaodong101010 2008-09-10
  • 打赏
  • 举报
回复
select distinct(a.objid),a.*,u.username as objusername from usr_action_other a,usr_user u where a.type=1 and a.username=u.username and a.objid=u.userid and a.username='%s' order by a.crtime desc limit %d,%d

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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