2
我們希望找到有員工誰可以做的員工做了一些工作在depertment 20以下兩個查詢是否會一致提供相同的輸出?
SELECT deptno
FROM dept
WHERE EXISTS(SELECT *
FROM emp x
WHERE x.deptno = 20
AND EXISTS(SELECT *
FROM emp y
WHERE y.job = x.job
AND y.deptno = dept.deptno))
AND deptno <> 20;
SELECT deptno
FROM dept
WHERE EXISTS(SELECT *
FROM emp x
WHERE x.deptno = dept.deptno
AND EXISTS(SELECT *
FROM emp y
WHERE y.job = x.job
AND y.deptno = 20))
AND deptno <> 20;
'x'和'y'不能相同,因爲'x.deptno = 20'和'y.deptno <> 20'或反之亦然。 – 2011-12-28 13:53:01
@ypercube:好點!看起來像我誤解了這個問題。我會編輯答案。 – Andomar 2011-12-28 14:01:21