MYSQL INSERT INTO WITH SELECT无法正常工作?

时间:2014-03-28 00:42:37

标签: mysql sql

我正在尝试使用SELECT进行插入,以下查询似乎不会因某些原因而起作用,

INSERT INTO `employer_data` 
(`employer_id`, `data`, `datetime`) 
VALUES 
( SELECT employer_id, employer_id AS data, NOW() AS `datetime` FROM employer ); 

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

删除values关键字

INSERT INTO `employer_data` 
(`employer_id`, `data`, `datetime`)  
( SELECT employer_id, employer_id AS data, NOW() AS `datetime` FROM employer ); 

答案 1 :(得分:1)

语法错误。

尝试:

INSERT INTO `employer_data` 
(`employer_id`, `data`, `datetime`) 
SELECT employer_id, employer_id AS data, NOW() AS `datetime` FROM employer;

参阅
MySQL: INSERT ... SELECT Syntax