The so-called subquery is the embedding of several small queries within a query.
Grammar:
Select "Distinct" * | column name "Alias", Column name "Alias" ... | Statistical functions, (
select "DISTINCT" *| column name "Alias", Column name "Alias" ... | Statistical functions
From data table "alias", Data table "Alias" ...
"Where condition (s)"
"Group by Group field, Group field, ..."
"Having group after filter"
"Order By Field" Asc|desc ", Field" Asc|desc ",......"
)
From data table "alias", Data table "Alias",......,select "DISTINCT" *| column name "Alias", Column name "Alias" ... | Statistical functions
From data table "Alias", Data table "Alias" ...
"Where condition (s)"
"Group by Group field, Group field, ..."
"Having group after filter"
"ORDER By Field" Asc|desc ", Field" Asc|desc ",......";
The Where condition (s) (select "DISTINCT" *| column name "Alias", Column name "Alias" ... | Statistical functions
From data table "Alias", Data table "Alias" ...
"Where condition (s)"
"Group by Group field, Group field, ..."
"Having group after filter"
"ORDER By Field" Asc|desc ", Field" Asc|desc ",......")】
"Group by Group field, Group field, ..."
"Having a group after filtering,select "DISTINCT" *| column name "Alias", Column name "Alias" ... | Statistical functions
From data table "Alias", Data table "Alias" ...
"Where condition (s)"
"Group by Group field, Group field, ..."
"Having group after filter"
"ORDER By Field" Asc|desc ", Field" Asc|desc ",......"】
"Order By Field" Asc|desc ", Field" Asc|desc ",......"
The subquery returns a single-row column: Having, where
The subquery returns a multiple-row column: where
Subquery returns multiple rows and columns: from
Subqueries can also appear in the SELECT clause, but this is rarely done in general. At the same time, the subquery must have "()"when it appears.
Use a subquery in the WHERE clause.
This article is from the "10281302" blog, please be sure to keep this source http://10291302.blog.51cto.com/10281302/1691431
Sub-query (most difficult)