Mysql Chapter 9 [Subquery]

Subquery classification

Divided into 4 types according to the number of rows and columns of the result set

Standard quantum query (the result set has only one row and one column)

Column subquery (the result set has only one column and multiple rows)

Row subquery (the result set has one row with many columns)

Table subquery (the result set is generally multiple rows and columns)

According to the different positions of the subquery in the main query

After select: only supports standard quantum query.

From behind: Support table subquery.

behind where or having: support standard quantum query (single column and single row), column subquery (single column and multiple rows), row subquery (multiple columns and multiple rows)

Behind exists (that is, related subqueries): table subqueries (multiple rows, multiple columns)

Mysql execution order

  1. from
  2. on
  3. join
  4. where
  5. group by
  6. having
  7. select
  8. distinct
  9. union
  10. order by
  11. limit

Guess you like

Origin www.cnblogs.com/kwdlh/p/12733157.html