嗨,我不知道它爲什麼會產生不同的結果。有人能讓我知道我的錯誤是什麼?不存在和不在SQL服務器
該查詢返回2行的記錄
SELECT Prod.bintProductRef FROM Prod_ProfileTbl Prod
WHERE Prod.intDepartmentRef =4
bintProductRef
--------------------
164475
164476
和記錄
SELECT Prod.bintProductRef FROM Prod_ProfileTbl Prod
WHERE intCatRef = 132
bintProductRef
--------------------
164475
NOT EXISTS的這個查詢返回1行,當結合上面的2個查詢,它應該返回164476,但沒有輸出。
SELECT Prod.bintProductRef FROM Prod_ProfileTbl Prod
WHERE Prod.intDepartmentRef =4
AND NOT EXISTS (
SELECT Prod.bintProductRef FROM Prod_ProfileTbl Prod
WHERE intCatRef = 132)
NOT IN,這回1行數據,這是164476,這是正確的。
SELECT Prod.bintProductRef FROM Prod_ProfileTbl Prod
WHERE Prod.intDepartmentRef =4
AND Prod.bintProductRef NOT IN (
SELECT Prod.bintProductRef FROM Prod_ProfileTbl Prod
WHERE intCatRef = 132)
http://stackoverflow.com/questions/173041/not-in-vs-not-exists –