您好,登錄后才能下訂單哦!
exists后面的子查詢,exists 只關心有沒有,返回布爾類型
#案例:查詢有員工的部門名
SELECT department_name
FROM departments d
WHERE EXISTS(
SELECT *
FROM employees e
WHERE d.`department_id`=e.`department_id`
);
或
SELECT department_name
FROM departments
WHERE department_id IN(
SELECT department_id
FROM employees
);
#查詢沒有女朋友的男神信息
SELECT bo.*
FROM boys bo
WHERE NOT EXISTS(
SELECT b.boyfriend_id
FROM beauty b
WHERE b.`boyfriend_id`=bo.`id`
);
或
SELECT bo.*
FROM boys bo
WHERE bo.`id` NOT IN(
SELECT boyfriend_id
FROM beauty b
);
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。