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

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);  

你可能感兴趣的:(MySQL,子查询返回了多行数据,1242,Subquery,returns,more,than)