2010-06-21 63 views
0

今天我在想咖啡不夠強壯。我需要查詢表fb-celebotd以獲得與fb-celebotd.celebdate相匹配的照片。大部分其他需要的信息都依賴於照片表。我左邊的連接錯誤?

以下是給我一個MySQL錯誤:

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 

這是可行的在一個查詢或我必須首先查詢FB-celebotd爲PHOTOID和瑣事,然後查詢基礎上,PHOTOID其他表?

謝謝。

回答

3

應該fb-celebotd(帶短劃線)是fb_celebotd(帶下劃線)?如果表名有短劃線,則必須引用表名:"fb-celebotd"。否則,短劃線被視爲一個負號,並嘗試從fb中減去celebotd(都是未知的)。

+0

。謝謝你的第二套眼睛。更改了表名,它工作。 – Ian 2010-06-21 19:13:00

1

如果你真的有一個名爲FB-celebotd表,那麼你需要使用它在查詢中每次引用表名:我知道我的咖啡是弱

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