2013-04-27 102 views
0

下面的查詢將引發一個錯誤:多表連接拋出「不是唯一的表/別名」錯誤

SELECT * FROM proposal_data 
    INNER JOIN proposal_data 
     ON proposal_data_second.proposal_id = proposal_data.proposal_id 

    INNER JOIN proposal_data_second 
     ON proposal_data_third.proposal_id = proposal_data_second.proposal_id 
    INNER JOIN proposal_data_third 
     ON proposal_data_fourth.proposal_id = proposal_data_third.proposal_id 

的錯誤是:

#1066 - Not unique table/alias: 'proposal_data' 

我在做什麼錯?

+1

那麼究竟什麼是 「problum」? – 2013-04-27 07:02:18

+0

Mysql提供以下錯誤#1066 - 不是唯一表/別名:'proposal_data' – user2118352 2013-04-27 07:03:25

+1

首先,請閱讀錯誤消息:錯誤1066(42000):不是唯一表/別名:'proposal_data'。您需要使用表別名(例如,請參閱http://www.keithjbrown.co.uk/vworks/mysql/mysql_p8.php) – LSerni 2013-04-27 07:04:34

回答

1

您錯誤地加入了表格。

在你當前的查詢您聲明之前加入表:

例如取前三行

SELECT * FROM proposal_data 
    INNER JOIN proposal_data 
     ON proposal_data_second.proposal_id = proposal_data.proposal_id 

這裏您聲明proposal_data_second表之前proposal_data_second加盟proposal_data

而且你並不需要使用表名peoposal_data兩次:

SELECT * FROM proposal_data 
    INNER JOIN proposal_data --This is invalid syntax 

試試這個:

SELECT * FROM proposal_data 
    INNER JOIN proposal_data_second 
      ON proposal_data_second.proposal_id = proposal_data.proposal_id 
    INNER JOIN proposal_data_third 
      ON proposal_data_third.proposal_id = proposal_data_second.proposal_id 
    INNER JOIN proposal_data_fourth 
      ON proposal_data_fourth.proposal_id = proposal_data_third.proposal_id 

更多看到MySQL: JOIN Syntax

+1

「查詢錯誤」聽起來含糊不清,請解釋他或者丟棄他的位置出錯 – 2013-04-27 07:04:45

+0

@ Mr.Alien - Yeh更新。 – hims056 2013-04-27 07:09:55

+0

@ hims056 mysql顯示以下錯誤#1066 - 不是唯一表/別名:'proposal_data' – user2118352 2013-04-27 07:15:21

相關問題