2012-06-30 170 views
1
INSERT INTO `competitions` (`name`) VALUES SELECT `name` FROM `competitions` 

產生以下錯誤:INSERT INTO SELECT不起作用

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 'SELECT name FROM competitions ' at line 1

我可能忽視的東西微不足道,但我真的不明白我在做什麼錯在這裏。

+4

刪除'VALUES'。請參閱語法:http://dev.mysql.com/doc/refman/5.5/en/insert.html – biziclop

回答

4

正確的語法是

INSERT INTO `competitions` (`name`) SELECT `name` FROM `competitions` 

參考:INSERT ... SELECT Syntax

+1

+1提供指向文檔的鏈接 –

2

從您的查詢VALUES

這個語句的語法是:

INSERT INTO tbl_temp2 (fld_id) 
    SELECT tbl_temp1.fld_order_id 
    FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100; 

正確的語法是:

INSERT INTO `competitions` (`name`) 
    SELECT `name` FROM `competitions`