dspice Posted October 23, 2008 Share Posted October 23, 2008 i have 7 table student(sid, sname, sex, age, year, gpa) dept(dname, numphds) prof(pname, dname) course(cno, cname, dname) major(dname, sid) section(dname, cno, sectno, pname) enroll(sid, grade, dname, cno, sectno) i want to print the names of students who are taking both a computer science course and a math course. i know i have to use intersect but the attributes in student are not in course, how do i link the tables to get the info i want? Link to comment https://forums.phpfreaks.com/topic/129702-intersect/ Share on other sites More sharing options...
dilum Posted October 23, 2008 Share Posted October 23, 2008 THis might help you, "select * from student wher sid IN(select sid from enroll en, coures co where en.cno = co.cno and co.cname IN('computer','math'))" Link to comment https://forums.phpfreaks.com/topic/129702-intersect/#findComment-672772 Share on other sites More sharing options...
Barand Posted October 23, 2008 Share Posted October 23, 2008 This query uses the data from my tutorial (http://www.phpfreaks.com/tutorial/data-joins-unions) and lists those pupils taking English and German [pre] mysql> select p.pupil_name from pupil p -> INNER JOIN -> (SELECT pupilID FROM choice WHERE subjectID=1) as A -> USING(pupilID) -> INNER JOIN -> (SELECT pupilID FROM choice WHERE subjectID=2) as B -> USING(pupilID); +---------------+ | pupil_name | +---------------+ | Adam Simms | | Anne Bailey | | John Watson | | John Williams | +---------------+[/pre] Link to comment https://forums.phpfreaks.com/topic/129702-intersect/#findComment-673023 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.