1. 首页
  2. 软件开发
  3. 数据库
  4. 关于mysql错误:Subquery returns more than 1 row

关于mysql错误:Subquery returns more than 1 row

  • 发布于 2024-09-25
  • 1 次阅读

EXPLAIN select * from mytable where shouji = (select shouji from mytable GROUP BY shouji HAVING count(shouji)>2)
> 1242 - Subquery returns more than 1 row
> 时间: 0.002s

这个错误是:子查询返回了多行数据

解决方法:

以

select * from mytable where shouji = (select shouji from mytable GROUP BY shouji HAVING count(shouji)>2);

为例。

1)在子查询条件语句加limit 1,找到一个符合条件的就可以了
select * from mytable where shouji = (select shouji from mytable GROUP BY shouji HAVING count(shouji)>2 limit 1);
3)在子查询前加any关键字
select * from mytable where shouji = any(select shouji from mytable GROUP BY shouji HAVING count(shouji)>2);

原文链接: https://onlyou.blog.csdn.net//article/details/82967902