2012-03-15 106 views
0

我試圖加入一個附加的表我的查詢,我就遇到了這個錯誤:內側連接多個表

Not unique table/alias: 'events'

它發生時,我說:

events INNER JOIN party_types 
ON events.PARTY_TYPE = party_types.ID 

在我的代碼,現在看起來像這樣:

SELECT 
    events.EVENT_NAME, events.start_datetime, events.end_datetime, events.VENUE_LOCATION, events.PARTY_TYPE, events.IMAGE_URL, 
    venues.VENUE_NAME, 
    party_types.PARTYTYPE 
FROM 
    events INNER JOIN venues 
    events INNER JOIN party_types 
    ON events.VENUE_LOCATION = venues.ID 
    ON events.PARTY_TYPE = party_types.ID 
WHERE 
    start_datetime >= '$DATE_START_SELECTED' and end_datetime < '$DATE_END_SELECTED 

任何想法,爲什麼發生這種情況?謝謝:)

回答

4

這不是有效的語法。它被解釋如下:

FROM events 
INNER JOIN venues AS events 
INNER JOIN party_types 

第二events被解釋爲venues表的別名。 AS是可選的。

試試這個:

SELECT 
    events.EVENT_NAME, 
    events.start_datetime, 
    events.end_datetime, 
    events.VENUE_LOCATION, 
    events.PARTY_TYPE, 
    events.IMAGE_URL, 
    venues.VENUE_NAME, 
    party_types.PARTYTYPE 
FROM events 
INNER JOIN venues 
    ON events.VENUE_LOCATION = venues.ID 
INNER JOIN party_types 
    ON events.PARTY_TYPE = party_types.ID 
WHERE start_datetime >= '$DATE_START_SELECTED' 
AND end_datetime < '$DATE_END_SELECTED' 
+0

謝謝你馬克:)! – pufAmuf 2012-03-15 20:54:52