Question: SQL question and the answer is below. Could you explain the steps of the answer? Since I can not imagine why use minus and not
SQL question and the answer is below.
Could you explain the steps of the answer? Since I can not imagine why use minus and not exists can get the answer...
Q: List students who have enrolled in courses every year that courses were offered select studentid from enrolled e where not exists (select distinct year from enrolled where courseid=e.courseid minus select distinct year from enrolled where studentid=e.studentid and courseid=e.courseid)
(table for reference)

STUDENTID 11035 IT 11035 75234 8871 39077 57923 60973 19992 60973 90421 90421 60973 60973 wovon WN COURSEID QUARTER YEAR 1020 Fall 2012 1092 Fall 2012 3201 Winter 2012 1092 Fall 2013 1092 Fall 2013 9219 Winter 2013 9219 Winter 2013 3201 Winter 2013 8772 Spring 2013 8772 Spring 2013 2987 Spring 2013 2987 Spring 2013 3201 Fall 2012 *CID COURSENAME DEPARTMENT COURSENR 1 1020 Theory of Computation CSC 489 2 1092 Cryptography CSC 440 3 3201 Data Analysis 223 4 9219 Databases Systems CSC 355 5 3111 Theory of Computation CSC 389 6 8772 History of Games GAM 206 7 2987 Topics in Digital Cinema DC 270 STARTED 2010 2013 2009 2009 2010 2009 LASTNAME FIRSTNAME SID SSN CAREER PROGRAM 1 Brennigan Marcus 90421 987654321 UGRD COMP-GAM 2 Patel Deepa 14662 (null) GRD COMP-SCI 3 Snowdon Jonathan 8871 123123123 GRD INFO-SYS 4 Starck Jason 19992 789789789 UGRD INFO-SYS 5 Johnson Peter 32105 123456789 UGRD COMP-SCI 6 Winter Abigail 11035 111111111 GRD PHD 7 Patel Prakash 75234 (null) UGRD COMP-SCI 8 Snowdon Jennifer 93321 321321321 GRD COMP-SCI 9 Degroff Jarvis 14998 113311331 GRD COMP-GAM 10 Kubik Dwayne 57923 979797979 UGRD COMP-SCI 11 Skelly Trinity 58992 555222555 GRD PHD 12 Krol Angelo 60973 (null) UGRD COMP-SCI 13 Pollard Joya 39077 (null) GRD COMP-SCI CITY Evanston Evanston Springfield Springfield Chicago Chicago Chicago Springfield Evanston Springfield Springfield Springfield Springfield 2011 2012 2012 2013 2012 2011 2010
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
