[mysql语法错误]-Subquery returns more than 1 row

今天在学 子查询中遇到一个问题
当返回值为多值时 ,mysql抛出错误

表示子查询返回了多行数据

如下:

[21000][1242] (conn=11) Subquery returns more than 1 row

源代码为:

select * from emp where depno =(select deptno from dept where loc ='二区');

经查 只需要在返回值那里添加 any 即可

解决方案
如:

select * from emp where depno =any (select deptno from dept where loc ='二区');

也可加一个 in
如:

select * from emp where depno in (select deptno from dept where loc ='二区');

你可能感兴趣的:(学习经历,mysql,数据库)