Find the names of students who have selected all courses

Source: Internet
Author: User

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.

 

 


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.