The schema is as follows:
Student(Snum, Sname)
Course(Cnum, Cname)
Professor(Pnum,Pname, Dept, Office)
Class(Cnum, Term, Section, Instructor)
How can I join the two selects below to get Instructors who taught both CS160 and CS340?
SELECT DISTINCT Instructor FROM class
WHERE Term = "99F" AND Cnum = "CS160"
SELECT DISTINCT Instructor FROM class
WHERE Term = "99F" AND Cnum = "CS340"
Thanks!
Since MySql doesn’t have
intersect, you have to do a self-join; something like:Edit: with intersect, you just put the
intersectspecifier between the 2 queries you had in your example (and you can omit the “distinct”; “intersect” returns only distinct values):intersectis part of the SQL standard, but MySql doesn’t implement it. SQL implementations that do haveintersectinclude Oracle and Postgres.See also mySQL versus Standard SQL