问题是“显示职位名称与销售部门中任何人相同的所有员工的姓名”,但
SELECT name, job
FROM Employer WHERE job=(SELECT job FROM employer WHERE dept = sales);
不起作用,因为子查询返回多个值。我该如何解决这个问题?
答案 0 :(得分:4)
尝试使用in
SELECT name, job
FROM Employer
WHERE job in (SELECT job FROM employer WHERE dept = sales);
答案 1 :(得分:0)
in
关键字实际上只是join
。例如,您的查询与以下内容相同:
SELECT e1.name, e1.job
FROM Employer e1
JOIN Employer e2 on e1.job = e2.job
WHERE e2.dept = 'sales'