Since the Unique only works on the result which are exactly same. But here you are including IDs as well, which will be unique for each row making each record unique. So the result is showing all the records.
SELECT DISTINCT Review.user_id, Review.id, User.*, Account.*
FROM reviews As Review
INNER JOIN users AS User ON Review.user_id = User.id
LEFT JOIN accounts AS Account ON User.id = Account.user_id
GROUP BY Review.user_id
If you want only unique user_id's, try GROUP'ing by it. But this will truncate all other joined records from the result. So you better think what do you want to select with user_id and what you don't.
SELECT DISTINCT Review.user_id, Review.id, User.*, Account.*
FROM reviews As Review
INNER JOIN users AS User ON Review.user_id = User.id
LEFT JOIN accounts AS Account ON User.id = Account.user_id
GROUP BY Review.user_id
发布评论
评论(2)
由于“唯一”仅适用于完全相同的结果。但在这里您还包括
ID
,它对于每行都是唯一的,从而使每条记录都是唯一的。所以结果显示了所有记录。Since the Unique only works on the result which are exactly same. But here you are including
ID
s as well, which will be unique for each row making each record unique. So the result is showing all the records.如果您只想要唯一的 user_id,请尝试按它进行分组。但这将从结果中截断所有其他连接的记录。所以你最好想想你想用 user_id 选择什么,不想选择什么。
If you want only unique user_id's, try GROUP'ing by it. But this will truncate all other joined records from the result. So you better think what do you want to select with user_id and what you don't.