Created
October 8, 2014 08:19
-
-
Save blakewrege/cef543f752225ad92687 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT * from (enrolled left join class | |
on enrolled.cname=class.cname) | |
union | |
SELECT * from (enrolled right join class | |
on enrolled.cname=class.cname); | |
SELECT *from (class left join faculty | |
on class.fid=faculty.fid) | |
union | |
SELECT * from (class right join faculty | |
on class.fid=faculty.fid); |
This is crazy:
SELECT *
FROM (((student
left join enrolled
on student.snum=enrolled.snum)
left join class
on enrolled.cname=class.cname)
left join faculty
on class.fid=faculty.fid)
union
select *
FROM (((student
right join enrolled
on student.snum=enrolled.snum)
right join class
on enrolled.cname=class.cname)
right join faculty
on class.fid=faculty.fid);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
select student.sname, group_concat(class.cname), count(faculty.fid) as count
from student
inner join enrolled on student.snum = enrolled.snum
inner join class on class.cname = enrolled.cname
inner join faculty on faculty.fid = class.fid
group by student.sname, faculty.fid
having count(faculty.fid) = 2