我有三个表:player(playerId, Name)
,game(gameId, gameName)
和gameResults(gameId, playerId, results)
。
我想要从表gameResults
中不存在gameId
的{{1}}中检索行。
我的查询是:
game
我也试过了:
SELECT DISTINCT
gameresults.playerId,
gameresults.results
FROM
game,
gameresults,
player
WHERE
gameresults.playerId = player.playerId
AND gameresults.gameId NOT IN (
SELECT game.gameId; FROM game
)
答案 0 :(得分:1)
SELECT DISTINCT gameresults.playerId, gameresults.results, game.gameName
FROM gameresults
LEFT JOIN game ON game.gameId = gameresults.gameId
/ * WHERE gameresults.gameName Is NULL <-- incorrect */
WHERE gameresults.gameId IS NULL;
答案 1 :(得分:0)
SELECT * FROM gameResults
WHERE gameId NOT IN (SELECT gameid FROM game)
快速而肮脏,但易于理解