homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Help With JOIN Statements

 5:11 am on Mar 24, 2005 (gmt 0)

I think I need some help with implementing a JOIN statement. I have a situation where I have 2 tables: "events" & "photos". Events has 2 fields: "eventID", "name" and photos has 3 fields: "photoID", "filename" and "eventID". I need to create a select statement that will return events.eventID for events that appear in the eventID column of the photos table. All the JOIN statements I've used return a result for every record in the photos table that has an eventID, so that a query gives me 20 instances of events.eventID for every photo that is in the photos table.

My goal is to create a list of events that have photos associated with them, but instead I'm getting the events for every photo in the table. How should I construct my SQL statement?



 11:06 am on Mar 24, 2005 (gmt 0)

hi terry

sounds like a left join

select whatever
from events
left join photos
on events.eventID = photos.eventID

there's an excellent tutorial in w3schools which explains joins very clearly.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved