Martin AJ
Martin AJ

Reputation: 6697

MySQL - How can I insert multiple rows using select statement?

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

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

Upvotes: 1

Views: 63

Answers (3)

MarcM
MarcM

Reputation: 2251

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

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

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.

Upvotes: 1

Klodian
Klodian

Reputation: 713

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

Upvotes: 1

DineshDB
DineshDB

Reputation: 6193

Remove the VALUES key word from your Query.

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;

Upvotes: 1

Related Questions