mysql5.7innodb引擎底层分析:子查询种类回顾

子查询种类回顾

select * from (select m1 from t1 limit 1);  像这种只返回一个值的被称为标量子查询

select * from (select * from t1 limit 1);  像这种只返回一行数据的子查询被称为行子查询,会有多个列返回。

select * from (select m1 from t1 limit 10);  像这种返回一个列但是多行数据的子查询被称为列子查询

select * from t1 where (m1, n1) = (select m2, n2 from t2);       返回多行多列的就是表子查询

select * from t1 where m1 in ( select m2 from t2 where t1.id = t2.id );           子查询中有对外层关系的依赖,称为相关子查询

select * from t1 where m1 in ( select m2 from t2 );      子查询中没有对外层关系的依赖,称为不相关子查询

select * from t1 where m1 > ANY( select m2 from t2 );   等价于   select * from t1 where m1 > ( select min(m2) from t2 );

select * from t1 where m1 > ALL( select m2 from t2 );   等价于   select * from t1 where m1 > ( select MAX(m2) from t2 );

end.

posted on 2021-07-18 19:32  梦幻朵颜  阅读(99)  评论(0编辑  收藏  举报