views:

54

answers:

2

I'm thinking the coffee isn't strong enough today. I need to query the table fb-celebotd to get the photoid that matches the fb-celebotd.celebdate. Most of the other info needed is dependent on the photos table.

The following is giving me a mysql error:

Select photos.*,photographer.name, events.eventname, events.eventhome, subevents.subeventname, photodir.photodir, fb-celebotd.celebdate, fb-celebotd.trivia 
      from photos 
LEFT JOIN fb-celebotd ON (photos.photoid = fb-celebotd.photoid) 
LEFT JOIN photodir ON (photos.photodirid = photodir.photodirid) 
LEFT JOIN photographer ON (photos.photographerid = photographer.photographerid) 
LEFT JOIN events ON (photos.eventid = events.eventid) 
LEFT JOIN subevents ON (photos.subeventid = subevents.subeventid) 
WHERE fb-celebotd.celebdate=1277092800

Is this doable in one query or do I have to query fb-celebotd for the photoid and trivia first and then query other tables based on the photoid?

Thanks.

+3  A: 

Should fb-celebotd (with a dash) be fb_celebotd (with an underscore)? If the table name has a dash, then you'll have to quote the table name: "fb-celebotd". Otherwise the dash is treated as a minus sign and tries to subtract celebotd from fb (both unknown).

Scott Thomson
I knew my coffee was to weak. Thanks for the 2nd set of eyes. Changed the table name and it worked.
Ian
+1  A: 

If you really have a table named fb-celebotd, then you need to quote the table name every time you use it in a query:

Select photos.*,photographer.name, events.eventname, events.eventhome, subevents.subeventname, photodir.photodir, `fb-celebotd`.celebdate, `fb-celebotd`.trivia 
      from photos 
LEFT JOIN `fb-celebotd` ON (photos.photoid = `fb-celebotd`.photoid) 
LEFT JOIN photodir ON (photos.photodirid = photodir.photodirid) 
LEFT JOIN photographer ON (photos.photographerid = photographer.photographerid) 
LEFT JOIN events ON (photos.eventid = events.eventid) 
LEFT JOIN subevents ON (photos.subeventid = subevents.subeventid) 
WHERE `fb-celebotd`.celebdate=1277092800
Ike Walker