[SQL ] 語法上的差異性

看板Database作者 (天生我材)時間11年前 (2014/04/04 13:38), 編輯推噓0(005)
留言5則, 1人參與, 最新討論串1/1
(針對 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

04/04 19:07, , 1F
撇開上半部一樣的不看
04/04 19:07, 1F

04/04 19:08, , 2F
差別就在一個使用not exists 一個使用except
04/04 19:08, 2F

04/04 19:08, , 3F
except不就是排除嗎?當然就跟not exists一樣摟
04/04 19:08, 3F

04/04 19:10, , 4F
我覺得你會搞混是因為你想把一整句sql一次看完
04/04 19:10, 4F

04/04 19:11, , 5F
你可以試著從內圈的括弧開始看
04/04 19:11, 5F
文章代碼(AID): #1JFaLgYs (Database)