Subquery definition: Using a SELECT statement inside an external SQL statement, this SELECT statement is called a subquery
Sub-query type:
Single-line subquery: Either no results are returned for external SQL, or only one row is returned. Single-row subquery special case: Is this number of queries a column, this seed query is called
"Scalar Quantum Query"
Multiline subquery: Returns one or more rows to an external SQL statement
and sub-query can be divided into:
Dolez query: Returning a queue to an external SQL statement
Associated subquery (correlated Sbuquery): associated with an external SQL statement by the same column (one or more columns referencing an external SQL statement)
Nested subqueries: In another subquery
6.2 Writing a single-line subquery (which can be placed in the WHERE/HAVING/FROM clause)
1. Place in the WHERE clause
Select First_Name, last_name
From customers
where customer_id=
(Select customer_id
From customers
where last_name= "Brown");
This subquery in the WHERE clause executes first, returns the ID of the last_name= "Brown" line, and then passes it to the external WHERE clause to execute the external query.
Use other operators: <,<=,>,>=
For example
Select product_id, Name, price
Form Products
where prict>
(select AVG (Price)
From products)
2 using subqueries in a HAVING clause
The HAVING clause acts to filter a row group and use a subquery in the HAVING clause of an outer query: The HAVING clause returns based on a subquery
The result of filtering the row group
Moon subquery SQL