Jump to content

[SOLVED] Query from many to many relationship


jellis

Recommended Posts

Hi all,

 

Long time reader, first time poster.

 

I'm absolutely stuck.  I have the following table structure.

 

Presentations

pres_id

title

description

date

 

Speakers

speak_id

fname

lname

bio

 

Speakpres

sp_id

speak_id

pres_id

 

I've written a page to display the information from a presentation.  It queries the database based on the pres_id and returns those values... no problems.

 

The problem arises when I try to return the presenter(s) from the presentation.  I've tried numerous ways to return these values but I just cannot get it to work.

 

My latest idea was this:

 

"SELECT fname, lname FROM conf2007_speakers AS s, conf2007_speakpres AS sp WHERE sp.pres_id = '$pres_id' AND s.speak_id = sp.speak_id"

 

but this is obviously wrong...

 

Thanks for any input.

 

Josh

Link to comment
Share on other sites

Okay... I made another step (I think)... let me know if this is correct:

 

"SELECT * FROM conf2007_speakpres LEFT JOIN conf2007_speakers ON conf2007_speakpres.speak_id = conf2007_speakers.speak_id WHERE conf2007_speakpres.pres_id = '$pres_id'"

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.