【发布时间】:2014-04-16 15:58:28
【问题描述】:
我在网站和谷歌上到处找,没有找到我正在寻找的答案,我有 2 个表格,每个表格都有具体信息,报告给出了重复 我需要获取名称、反馈 ID 和最多具有 1 个反馈 ID 的站点。
这是我的 2 张桌子
表:反馈
userID | ID
john.smith |1
george.wilson |2
justin.example |3
justin.example |4
juliana.something |5
george.wilson |6
表:用户(此表上的其他信息给出了重复的原因)
UserID |Site
george.wilson |location 1
george.wilson |location 1
george.wilson |location 1
john.smith |Location 2
john.smith |Location 2
juliana.something |Location 3
justin.example |Location 4
justin.example |Location 4
当前查询
SELECT feedback.userID, feedback.id, Users.Site
FROM feedback
INNER JOIN users ON
feedback.userID = users.userid
WHERE feedback.userID <> 'x'
当前结果
UserID |ID | Sites
john.smith |1 |Location 2
john.smith |1 |Location 2
george.wilson |2 |location 1
george.wilson |2 |location 1
george.wilson |2 |location 1
justin.example |3 |Location 4
justin.example |3 |Location 4
justin.example |4 |Location 4
justin.example |4 |Location 4
juliana.something |5 |Location 3
george.wilson |6 |location 1
george.wilson |6 |location 1
george.wilson |6 |location 1
预期结果
UserID |ID | Sites
john.smith |1 |Location 2
george.wilson |2 |location 1
justin.example |3 |Location 4
justin.example |4 |Location 4
juliana.something |5 |Location 3
george.wilson |6 |location 1
我的查询已最小化,需要更多内容,但错误来自我的“内部联接”用户,谁能帮我解决这个问题? (我正在使用 My Sql Workbench 6.0) 提前谢谢你!
【问题讨论】:
-
选择不同的 feedback.userID、feedback.id、Users.Site
标签: mysql sql select join inner-join