Find the names of students who have selected all courses
Student table S (SNO int PK, Sn varchar (8) -- SnO indicates the student ID and Sn indicates the Student name.
Curriculum C (CNO int PK, CN varchar (50) -- CNO indicates the course number, and CN indicates the course name
Optional table SC (SNO int PK, CNO int PK, score number (), FK (SNO, CNO) -- score is the score.
-- The following statement is used to find the names of students who have selected all courses.
Select Sn
From S
Where (not exists
(Select *
From C
Where not exists
(Select *
From SC
Where SnO = S. SnO and CNO = C. CNO )))
Explanation: no course should be included in the course selected by the student.
The reason is that you do not know the access rules for fields. In the join query, the fields in the preceding table can be used as the conditions. The fields in the parent query table can be used as conditions in nested query subqueries.
Similar questions include:
1. Please take at least the names and student numbers of all the courses selected by student ID s003.
Select distinct Sn, SnO
From SC SC2
Where (not exists
(Select CNO
From SC SC1
Where SnO = 's003 'and CNO not in
(Select CNO from SC where sc2.sno = SC. SnO )))
Explanation:
No course number is selected by s003 student and is not included in the course number selected by the student.
Note that s003 does not mean the same thing here. This student generally refers to qualified students.