該查詢顯示正確的結果,但是在進行EXPLAIN時,它會將其列爲「依賴的子查詢」,我認爲它是不好的?從屬子查詢v左連接
SELECT Competition.CompetitionID, Competition.CompetitionName, Competition.CompetitionStartDate
FROM Competition
WHERE CompetitionID NOT
IN (
SELECT CompetitionID
FROM PicksPoints
WHERE UserID =1
)
我試圖改變查詢到這一點:
SELECT Competition.CompetitionID, Competition.CompetitionName, Competition.CompetitionStartDate
FROM Competition
LEFT JOIN PicksPoints ON Competition.CompetitionID = PicksPoints.CompetitionID
WHERE UserID =1
and PicksPoints.PicksPointsID is null
,但它顯示0行。上述與第一個查詢相比,究竟有什麼問題呢?
謝謝你,很好理解! – user1542043 2012-07-21 06:18:05
+1關於性能問題的很好的鏈接和好的建議,但是你不認爲'UserId <> 1'是OP的第一個查詢的更好的翻譯嗎? – 2012-07-21 06:24:00
'UserId <> 1'可能工作正常。我不確定哪個更清晰(或更少混淆:)) – 2012-07-21 06:53:30