[SQL ] not exist與not in的差別
(針對 SQL 語言的問題,用這個標題。請用 Ctrl+Y 砍掉這行)
資料庫名稱:
資料庫版本:
內容/問題描述:
有一個資料庫的表格 Table,欄位如下:
訂單號碼、訂單明細、訂單日期、供應商代號、供應商名稱、供應商地址、供
應商聯絡人、電話、料號、品名、規格、數量、單位、單價、金額、備註
(其中,有劃底線的是鍵值。一張訂單可以購買好幾項物品,每一項一行,而「訂單明
細」是訂單的項次,其值為1,2,3,…)
有那一個供應商,我們只和他買很貴(單價超過 5 萬元)的東西?
not exist與not exist的寫法
Select 供應商代號,供應商名稱
From Table A
where not exists
(Select *
From Table B
where 單價>50000 and not exists
(Select *
From table C
where B.料號=C.料號
and A.供應商代號=C.供應商代號)
)
not IN的寫法
Select 供應商代號,供應商名稱
From Table A
where 供應商代號 NOT IN
(Select 供應商代號
From Table B
Where 單價<=50000)
想問一下這2句SQL為什麼出來的結果不一樣呢?
not exist....not exist為什麼會錯呢??
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.243.242.63
※ 文章網址: http://www.ptt.cc/bbs/Database/M.1404995148.A.3BE.html
→
07/10 22:05, , 1F
07/10 22:05, 1F
討論串 (同標題文章)