Mysql 子查詢效率優化
一、MySQL子查詢的位置
1 2 3 |
create table t1 (k1 int primary key , c1 int );
create table t2 (k2 int primary key , c2 int );
insert into t2 values (1, 10), (2, 2), (3,30);
|
1 2 |
mysql> select t1.c1, ( select t2.c2 from t2) from t1, t2;
Empty set (0.00sec)
|
1 2 |
mysql> insert into t1 values (1, 1), (2, 2), (3, 3);
Query OK, 3 rows affected (0.00 sec)
|
1 2 |
mysql> select t1.c1, ( select t2.c2 from t2) from t1, t2;
ERROR 1242(21000): Subquery returns more than 1 row
|