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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started