Question: Question about SQL and not exists clause Given this schema: Professors (pid, pname, dept, ext.). Students (sid, sname, major-dept, year) Courses (cid, cname, dept, credithours)

Question about SQL and "not exists" clause

Given this schema:

Professors (pid, pname, dept, ext.).

Students (sid, sname, major-dept, year)

Courses (cid, cname, dept, credithours)

Enrollment (sem-year, sid, cid, grade)

Teach (pid, cid, sem-year, class_size)

Q: sid's of students enrolled in "spring 2017" every 3 credit hr course offered by "cs" department:

Answer:

Select sid from Students s where not exists (

(select c.cid from Courses c where c.dept= CS and c.credithours= 3)

except

(select e.cid from Enrollment e where e.sid=s.sid and sem-year = Spring2017))

I need an in-depth explanation for why/how this works, as well as an explanation of how the not exists clause works.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!