0

我有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'

请帮忙。

4

1 回答 1

1

看起来你大部分都拥有它。最后的 user_games.id_user<>1 可能不是您想要的,因为您正在寻找 id_user 为空且 null<>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
于 2013-04-09T21:48:21.357 回答