



t.mgr不就是那六個數字嗎,為什么查詢結果不一樣?
uj5u.com熱心網友回復:
select distinct e.ename from emp e join (select distinct mgr from emp where mgr is not null ) t on e.empno not in (t.mgr);上面是你的第一個sql。結果是14條記錄,也就是全部記錄,沒有過濾。
主要問題就是紅字的部分“join”,應改寫為“inner join”。
你的陳述句實際效果是以左側的"emp e"為準,沒有關聯到的記錄也會顯示。相當于left join的效果。
uj5u.com熱心網友回復:
In MySQL, JOIN, CROSS JOIN, and INNER JOIN are syntactic equivalents (they can replace each other). In standard SQL, they are not equivalent. INNER JOIN is used with an ON clause, CROSS JOIN is used otherwise.
uj5u.com熱心網友回復:
on 后跟的是一個運算式,布林值。on e.empno 的值是真是假,取決于你的兩種陳述句的執行計劃,用explain看一下。
你的sql陳述句存在bug,請改成 on e.empno=t.mgr。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/19832.html
標籤:MySQL
