標籤:
1單值(Scalar operand)
只有當外層(Parent)不為空白時,才返回相應值;否則返回NULL。
note:For the subquery just shown, if t1 were empty, the result would be NULL even though s2 is NOT NULL.
2 用於操作符比較
[14.2.10.2 Comparisons Using Subqueries]
non_subquery_operand comparision_operator (subquery)
the comparision_operator is :=,>,>=,<,<=,!=,like ,<=>[和=功能相似,也可用於NULL值比較]
3 使用IN,ANY,SOME
operand comparison_operator ANY (subquery)
operand IN (subquery)
operand comoparison_operator SOME (subquery)
where comparison_operator is one of these operators:=,>, >=,<,<=,<>,!=
ANY,說明任何一個。只要右側運算元中的任一個滿足運算元條件,就為true.[ANY (不能是常量值)]
IN,包含[可以有常量值,多個用","分隔]。
SOME 與ANY 在功能上等價,只是在日常文法上不同。
4,使用ALL
operand comparison_operator ALL (subquery)
滿足所有,才返回true.
5, 行子查詢[Row subqueries]
值或列子查詢(如上所示)返回一個值或合格一列值;行子查詢返回一行資料,可能有多個列;行子查詢的合法操作符為:
=,>,<,>=,<=,<>,!=,<=>
只有多列同時滿足操作符才返回true,否則為false or NULL.
6,使用 EXISTS OR NOT EXISTS
當子查詢返回有資料時,EXISTS subquery 為true,AND NOT EXISTS subquery 為false.
7,關聯子查詢
是含有對外層查詢有引用的查詢。
8 用於From子句
9.子查詢錯誤
10,最佳化子查詢
【Development is ongoing,so no optimization tip is reliable for the long term.】開發進行中時,從長期發展看沒有可靠的最佳化技巧。
Mysql子查詢