MySQL进行子查询(嵌套查询)时报错:Subquery returns more than 1 row

Subquery returns more than 1 row

子查询返回了多行数据

原因:子查询的时候返回了多条数据

报错代码:

SELECT * FROM emp WHERE deptno = (SELECT deptno FROM dept WHERE loc = '苏州');

解决方案一:使用ANY

SELECT * FROM emp WHERE deptno = ANY(SELECT deptno FROM dept WHERE loc = '苏州');

解决方案二:使用IN

SELECT * FROM emp WHERE deptno IN(SELECT deptno FROM dept WHERE loc = '苏州');
posted @ 2021-08-12 16:13  贪玩的阿柒  阅读(1021)  评论(0编辑  收藏  举报