MySQL - 如何使用select语句插入多行?

时间:2018-04-09 07:30:53

标签: mysql sql

这是我的问题:

insert into unique_products values (product_id, serial_numnber, pronexo_code, entry_time, exit_time, guarantee_long, expanded_guarantee_long)
select product_id, serial_number, pronexo_code, start_guarantee_date, start_guarantee_date, guarantee_long, expanded_guarantee_long
from table_24

它会抛出此错误消息:

  

#1064 - 您的SQL语法出错;检查与您的MySQL服务器版本相对应的手册,以便选择product_id,serial_number,pronexo_code,start_guarantee_date,start_guar'在第2行

有人知道问题是什么,我该如何解决?

3 个答案:

答案 0 :(得分:1)

从您的查询中删除VALUES关键字。

试试这个:

INSERT INTO unique_products (product_id, serial_numnber, pronexo_code, entry_time, exit_time, guarantee_long, expanded_guarantee_long)
SELECT product_id, serial_number, pronexo_code, start_guarantee_date, start_guarantee_date, guarantee_long, expanded_guarantee_long
FROM table_24;

答案 1 :(得分:1)

试试这个:

  insert into unique_products (product_id, serial_numnber, 
  pronexo_code, entry_time, exit_time, guarantee_long, 
  expanded_guarantee_long)
  select product_id, serial_number, pronexo_code, start_guarantee_date, 
  start_guarantee_date, guarantee_long, expanded_guarantee_long
  from table_24

答案 2 :(得分:1)

注意SQL语法和字段名称输入:

此处

VALUE关键字不正确,请注意serial_numnberserial_number字段名称的正确拼写:

insert into unique_products (product_id, SERIAL_NUMBER, pronexo_code, entry_time, exit_time, guarantee_long, expanded_guarantee_long)
select product_id, SERIAL_NUMBER, pronexo_code, start_guarantee_date, start_guarantee_date, guarantee_long, expanded_guarantee_long
from table_24

有关正确 INSERT-INTO-SELECT 语法here的详细信息。