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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.