Mysql ERROR 1242 (21000): Subquery returns more than 1 row

年夜雪

关注

阅读 52

2022-08-02


mysql> select count(*) from t1 where t1.id = (select t2.id from t2);
ERROR 1242 (21000): Subquery returns more than 1 row

解决方案,当然,两者的含义也不一样,需要自行判断。

mysql> select count(*) from t1 where t1.id = any(select t2.id from t2);
+----------+
| count(*) |
+----------+
| 959368 |
+----------+
1 row in set (2.12 sec)

mysql> select count(*) from t1 where t1.id = (select t2.id from t2 limit 1);
+----------+
| count(*) |
+----------+
| 2 |
+----------+
1 row in set (0.01 sec)

版权声明:本文为博主原创文章,未经博主允许不得转载。

MYSQL

精彩评论(0)

0 0 举报