jellis Posted May 3, 2007 Share Posted May 3, 2007 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 https://forums.phpfreaks.com/topic/49749-solved-query-from-many-to-many-relationship/ Share on other sites More sharing options...
jellis Posted May 3, 2007 Author Share Posted May 3, 2007 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 https://forums.phpfreaks.com/topic/49749-solved-query-from-many-to-many-relationship/#findComment-244001 Share on other sites More sharing options...
bubblegum.anarchy Posted May 3, 2007 Share Posted May 3, 2007 Try something like this: SELECT concat_ws(' ', lname, fname) AS speaker_name FROM Speakers INNER JOIN Speakpres ON Speakpres.pres_id = $pres_id AND Speakers.speak_id = Speakpres.speak_id Link to comment https://forums.phpfreaks.com/topic/49749-solved-query-from-many-to-many-relationship/#findComment-244091 Share on other sites More sharing options...
jellis Posted May 4, 2007 Author Share Posted May 4, 2007 Thankyou for your help. My left join is working for the time being, but I will change it to the inner join that you speak of and that will reduce it to one query only. Thankyou so much! Link to comment https://forums.phpfreaks.com/topic/49749-solved-query-from-many-to-many-relationship/#findComment-244932 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.