Note: All underscore + italic statements are optional statements
Subquery:
A Select statement that appears in a Where clause is called a subquery
The subquery returns a collection that can be compared to this collection to determine another query collection
Equivalent to nested query
SQL statement: expression not in (subquery)
Note: Of course only one column can be mapped in a subquery! Otherwise, it cannot be used as a "value" to participate in the operation
Example: ①List all the information of Zhang San and Wang San
Select * From Student Where Sname in('Zhang Yu', 'Wang San');
②List the names of all the students who have not taken the course taught by Mr. Li Ming
Select Sname From Student Where St not in (Select St From SC, Course C, Teacher T Where T.Tname='李明' and SC.Ct=C.Ct and T.Tt=C.Tt);
Uncorrelated subqueries :
The inner query is carried out independently, and there is no subquery involving any information related to the outer query
Correlated subqueries :
The inner query needs to rely on certain parameters of the outer query as a sub-query to be performed
Example: Names of students who have studied course No. 001
Among them, Student has an alias Stud, and this alias is used in the inner subquery
Then this is the correlated subquery
Correlated subqueries can only pass parameters from the outer layer to the inner layer, but not vice versa. This is also called the scoping principle of variables