作者oklp1415 (天生我材)
看板Database
標題[SQL ] 語法上的差異性
時間Fri Apr 4 13:38:48 2014
(針對
SQL 語言的問題,用這個標題。請用 Ctrl+Y 砍掉這行)
資料庫名稱:
MySQL
資料庫版本:
內容/問題描述:
兩個語法是這樣的
1.
select no,name
from clerk
where not exists(
(select book_no from book where auth='lee')
except
(select book_no
from trade_detail natural join trade
where trade.no=clerk.no));
2.
select no,name from clerk
where not exists(
select * from book where auth='lee' AND NOT EXISTS (
select * from trade natural join trade_detail
where trade.no=clerk.no AND trade_detail.book_no=book.book_no));
以上兩個語法結果是相同的結果
問題是不懂not exists+except的做何種的運算方式??
跟not exists做兩次是一樣的運算
不知道有人肯幫分析一下not exists之後接except 是怎樣的執行結果??
小的難以頓悟~"~感謝幫忙!!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.39.6.229
※ 文章網址: http://www.ptt.cc/bbs/Database/M.1396589930.A.8B6.html
→ bohei:撇開上半部一樣的不看 04/04 19:07
→ bohei:差別就在一個使用not exists 一個使用except 04/04 19:08
→ bohei:except不就是排除嗎?當然就跟not exists一樣摟 04/04 19:08
→ bohei:我覺得你會搞混是因為你想把一整句sql一次看完 04/04 19:10
→ bohei:你可以試著從內圈的括弧開始看 04/04 19:11