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

时间:2022-07-04 23:03:07

Here is my query:

这是我的查询:

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

It throws this error message:

它抛出此错误消息:

#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 'select product_id, serial_number, pronexo_code, start_guarantee_date, start_guar' at line 2

#1064 - 您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在第2行的“select product_id,serial_number,pronexo_code,start_guarantee_date,start_guar”附近使用正确的语法

Does anybody know what's the problem and how can I fix it?

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

3 个解决方案

#1


1  

Remove the VALUES key word from your Query.

从查询中删除VALUES关键字。

Try this:

尝试这个:

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  

try this :

尝试这个 :

  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

#3


1  

Take care at the SQL syntax and at the field name typing:

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

VALUE keyword is incorrect here, and watch serial_numnber or serial_number correct spelling for your field name:

VALUE关键字在这里不正确,并观察serial_numnber或serial_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

Details on correct INSERT-INTO-SELECT syntax here.

有关正确INSERT-INTO-SELECT语法的详细信息,请参见此处。

#1


1  

Remove the VALUES key word from your Query.

从查询中删除VALUES关键字。

Try this:

尝试这个:

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  

try this :

尝试这个 :

  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

#3


1  

Take care at the SQL syntax and at the field name typing:

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

VALUE keyword is incorrect here, and watch serial_numnber or serial_number correct spelling for your field name:

VALUE关键字在这里不正确,并观察serial_numnber或serial_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

Details on correct INSERT-INTO-SELECT syntax here.

有关正确INSERT-INTO-SELECT语法的详细信息,请参见此处。