[英]Selecting multiple rows with a sub-query
The question asks "Display the names of all employees whose job title is the same as anyone in the sales dept" but 该问题询问“显示其职务与销售部门中任何人相同的所有雇员的姓名”,但
SELECT name, job
FROM Employer WHERE job=(SELECT job FROM employer WHERE dept = sales);
does not work because the sub-query returns more than one value. 不起作用,因为子查询返回多个值。 How do I work around this?
我该如何解决?
Try to use in
尝试
in
SELECT name, job
FROM Employer
WHERE job in (SELECT job FROM employer WHERE dept = sales);
@Parado has the simplest solution. @Parado具有最简单的解决方案。 Keep in mind, however, that the
in
keyword is really just a join
. 但是请记住,
in
关键字实际上只是一个join
。 For example, your query is the same as: 例如,您的查询与:
SELECT e1.name, e1.job
FROM Employer e1
JOIN Employer e2 on e1.job = e2.job
WHERE e2.dept = 'sales'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.