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? Quote 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'))" Quote 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] Quote Link to comment https://forums.phpfreaks.com/topic/129702-intersect/#findComment-673023 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.