我有是非常緩慢運行查詢:MySQL的子查詢優化
SELECT *
FROM games
WHERE games.platform =13
AND games.id NOT
IN (SELECT game_id
FROM collections
WHERE collections.user_id =1)
我試圖把它改寫爲左加入,但它返回0結果:
SELECT *
FROM games
LEFT JOIN collections ON collections.game_id = games.id
WHERE collections.game_id IS NULL AND collections.user_id = 1 AND games.platform = 13
ORDER BY games.name ASC
莫非有人指出我的錯誤在這裏?
嘗試使用#FULL OUTER JOIN因爲它會指向你所有的東西,而不匹配的東西將返回爲空。 – B4NZ41 2011-03-17 19:59:12