select * from departments
DEPARTMENT_ID DEPARTMENT_NAME MANAGER_ID LOCATION_ID
10 Administration 200 1700
20 Marketing 201 1800
50 Shipping 124 1500
60 IT 103 1400
80 Sales 149 2500
90 Executive 100 1700
110 Accounting 205 1700
190 Contracting 1700
--------------------------------
SELECT department_id, department_name
FROM departments d
WHERE NOT EXISTS (SELECT 'X'
FROM employees
WHERE department_id
= d.department_id);
DEPARTMENT_ID DEPARTMENT_NAME
190 Contracting
为什么会有190显示,190明明有匹配啊,求解。
------解决方案--------------------
- SQL code
--说明这条语句选不出结果,也就是employees中不存在部门为190的记录SELECT 'X' FROM employees WHERE department_id=190;
------解决方案--------------------
190只是存在departments,还要看employees