Skip to content

Instantly share code, notes, and snippets.

@khalefa-phd
Last active February 22, 2021 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khalefa-phd/1e3ea11006e4b9dbf3056bac9d358877 to your computer and use it in GitHub Desktop.
Save khalefa-phd/1e3ea11006e4b9dbf3056bac9d358877 to your computer and use it in GitHub Desktop.
Problem no 6
-- correct but not for mysql
SELECT s.sid,s.lname, s.fname
FROM course c, student s, enrolled e
where c.cid=e.cid and e.sid=s.sid and c.`name`='network'
Intersect (
SELECT s.sid,s.lname, s.fname
FROM course c, student s, enrolled e
where c.cid=e.cid and e.sid=s.sid and c.`name`='database');
-- version 1
SELECT s.sid,s.lname, s.fname
FROM course c, student s, enrolled e
where c.cid=e.cid and e.sid=s.sid and c.`name`='network'
and EXISTS(
SELECT *
FROM course c1, student s1, enrolled e1
where c1.cid=e1.cid and e1.sid=s1.sid and c1.`name`='database'
and s.sid=s1.sid
);
-- version 2
SELECT
s.fname, s.lname
FROM STUDENT s1, enrolled e1, course c1, student s, enrolled e, course c
where s1.sid=e1.sid and e1.cid=c1.cid and s.sid=e.sid and e.cid=c.cid
and s1.sid=s.sid
AND ( c1.`name`='database' AND c.`name`='network');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment