Loading

MySQL子查询subquery

子查询(Subquery)是指出现在其他SQL语句内的SELECT子句。

例如:

select * from t1 where col1=(select col2 from t2);

其中select * from t1,称为Outer Query/Outer Statement(外层查询)

select col2 from t2,称为SubQuery(子查询)

 

子查询必须嵌套在查询内部,且必须始终出现在圆括号内

子查询可以包含多个关键字或条件,

如distinct  group by  order by  limit  函数等

子查询的外层查询可以是select  insert  update  set    或 do

子查询返回值

子查询可以返回标量、一行、一列或子查询。

posted @ 2017-03-02 20:12  王树燚  阅读(774)  评论(0编辑  收藏  举报