Jump to content

intersect


dspice

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.