50 Query Series-Seventh query: Inquiry Learn the student's number and name of all the classes taught by the teacher "Cotyledons"

Source: Internet
Author: User

The effect is:

We found out that the ID of the Cotyledons teaching class is 002 and 016. The students we elect have both courses at the same time.

As follows:

--------------------------------------------------------------------------------------------------------------- ----------------------------------

Specific practices:


First step: Find the ID of the cotyledons

Select Tblteacher. Teaid from Tblteacher where Tblteacher. Teaname= ' cotyledons '--Find out the ID of cotyledons teacher

Step Two: Find the ID of the class on cotyledons

Select Tblcourse. CourseID from Tblcourse where Tblcourse. Teaid=
(
Select Tblteacher. Teaid from Tblteacher where Tblteacher. Teaname= ' cotyledons '--Find out the ID of cotyledons teacher
)--The course ID of the class cotyledons teacher

Results:

And then you hit the problem card here.

The problems encountered are:

We're looking for people who have been in these two classes (001,016) That's what this person is:

How to check it?

Statement:
SelectSt. Stuid,st. Stuname fromTblstudent Stwhere  not EXISTS(/*the conditions to be met are: 1: ID of Chayeping (two) 2: two ID of cotyledons (as a whole) cannot be included in my student's corresponding list of the ID of the course*/SelectTblcourse. CourseID fromTblcoursewhereTblcourse. Teaid=(SelectTblteacher. Teaid fromTblteacherwhereTblteacher. Teaname='cotyledons'--find out the ID of cotyledons teacher) andTblcourse. CourseID not inch(SELECTTblscore. CourseID fromTblscoreWHERETblscore. Stuid=St. STUID))

Here is a description of not exists.

not EXISTS(... )

。。。 The result is that it returns true, but because it is not, it becomes false, so select does not return anything.

。。。 To find out that there is no result then return is false. But because not. So it becomes true, then select returns the query result.

50 Query Series-Seventh query: Inquiry Learn the student's number and name of all the classes taught by the teacher "Cotyledons"

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.