# #子查询
The query in parentheses is called a subquery, also called an internal query, which executes before the main query.
The result of the subquery is the main query (external query) using EXPR operator including the comparison operator.
-
-
- Single-line operators:>, =, >=, <, <>, <=
- Multiline operator: In, any, all
A subquery can be embedded in the following SQL clause:
-
- WHERE clause
- HAVING clause
- FROM clause
Sub-query usage guidance
-
-
- Sub-query to expand with the expansion number
- Place a subquery to the right of the comparison operator
- The ORDER BY clause in a subquery is not required unless you are performing a top-n analysis
- To use single-line operators for single-line subqueries
- To use multiline operators for multiline subqueries
#子查询类型
#单行子查询
Single-line subquery
-
- Subqueries return only one row
- Using the single-line operator
-
- Using group functions in subqueries
Check the employee's name, position and salary at the lowest wage
Department number and minimum wage for the minimum wage of 20 departments
#多行子查询
Multiline subquery, the number of rows that a subquery returns a record can be one or more bars.
Multi-row subqueries require the use of multiline operators.
Common multiline operators include the following:
The in operator is consistent with the previously described function and determines whether any one of the subquery's return values is the same. The returned result can be one or more.
#IN
#ANY: Indicates arbitrary.
< any is smaller than any result returned by the subquery, which is less than the maximum value of the returned result.
= any and any of the results in a subquery are equal, equivalent in.
> any is larger than any result returned by a subquery, which is greater than the minimum value of the returned result.
#ALL: Denotes all.
< All results are smaller than the subquery returns, which is less than the minimum value of the returned result.
> All results are larger than the subquery returns, which is greater than the maximum value of the returned result.
= all meaningless and logically not tenable.
# #多列子查询
So far you have been able to complete single-row and multiline subqueries, but only one column is compared in the WHERE or HAVING clause of the SELECT statement.
If you want to compare multiple columns, you must write a compound WHERE clause with a logical operator.
Dolez queries allow you to combine multiple conditions in a WHERE clause into a single
Multi-column comparison
Database of Neusoft Internship (7)--subquery