2014-04-24 163 views
0

出於某種原因,運行下面的代碼時,我收到以下錯誤:MySQL的語句返回語法錯誤

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM postcodes_demographics INNER JOIN latlon1 on postcodes_demographics.postc' at line 3 

我不明白我在做什麼錯了,感謝您的任何建議!

INSERT INTO pslatlong 
    SELECT postcodes_demographics.*, latlon1.*, 
    FROM postcodes_demographics 
    INNER JOIN latlon1 
    on postcodes_demographics.postcode = latlon1.postcodens; 
+3

刪除'select'子句末尾的逗號。 –

回答

1

你有一個錯誤的逗號:

SELECT postcodes_demographics.*, latlon1.*, <--- HERE 

刪除它。

0

這可能工作:

INSERT INTO pslatlong 
SELECT postcodes_demographics.*, latlon1.* 
FROM postcodes_demographics 
INNER JOIN latlon1 
on postcodes_demographics.postcode = latlon1.postcodens; 
1

我是,如果僅僅是刪除逗號修復這個問題非常驚訝。當使用insert,你應該在明確列出所有列的習慣:

INSERT INTO pslatlong(col1, col2, . . .) 
    SELECT d.col1, l.col2, . . . 
    FROM postcodes_demographics d INNER JOIN 
     latlon1 ll 
     on d.postcode = ll.postcodens; 

你需要這樣做,以確保正確的列分配權值,允許自動遞增的列可自動 - 增加,並防止根據列數的問題。