我有3张桌子,
user { id, name, email }
games { id, name, icon }
user_games {id_user, id_game}
我想选择用户没有的游戏。
这是我最好的尝试,但什么都不返回。但最后不要给出错误信息XD
SELECT a.*
FROM games a
LEFT JOIN user_games b ON a.id IN (b.id_game) AND '1' IN (b.id_user)
WHERE (b.id_game IS NULL) AND b.id_user <> '1'
请帮忙。
答案 0 :(得分:1)
看起来你大多拥有它。最后的user_games.id_user&lt;&gt; 1可能不是您想要的,因为您正在查找id_user为null且null&lt;&gt; 1的情况也为空。
SELECT games.*
FROM games
LEFT JOIN user_games on (
games.id = user_games.id_game AND
user_games.id_user = '1'
)
WHERE user_games.id_user IS NULL