为了简化这个问题,我使用了以下命令:
SELECT DISTINCT a.*, b.shortmessage
FROM `users` a, `rating` b
WHERE a.userid IN (333333, 101010)
AND b.myuserid IN (333333, 101010)
AND b.userid LIKE '000000'
它返回:
id other_columns shortmessage
3 Guy1 message from guy1
9 Guy2 message from guy1
3 Guy1 message from guy2
9 Guy2 message from guy2
请注意,我可以使用GROUP BY id
,它会按预期显示2行,但来自表2的消息在guy2上会出错。
我想要的是什么:
id other_columns shortmessage
3 Guy1 message from guy1
9 Guy2 message from guy2
答案 0 :(得分:0)
这些项目都是截然不同的(请查看hibernate
每shortmessage
}个不同的内容:
id
答案 1 :(得分:0)
我从w3s
快速阅读了INNER JOIN解决方案:
SELECT * FROM `users` INNER JOIN `rating` ON users.userid=rating.myuserid WHERE users.userid IN (333333, 101010) AND rating.myuserid IN (333333, 101010) AND rating.userid LIKE '000000'