Welcome to WebmasterWorld Guest from 54.159.26.69

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Help With JOIN Statements

     

TheRealTerry

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

10+ Year Member



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?

jamie

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

WebmasterWorld Senior Member 10+ Year Member



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.

hth

 

Featured Threads

Hot Threads This Week

Hot Threads This Month