Home > OS >  SQL Update statment from file
SQL Update statment from file

Time:04-07

I have a table "Soft_orders" which has two columns "id_order(primary key)" & "id_customer". I have .sql file which has data for these two columns like the format below, (first value is id_order and second is id_customer)

(1, 1),
(2, 1),
(3, 1),
(4, 1),
(5, 1),
(6, 2),
(11, 2).........

I simply want to update the values of id_customer in the table by importing this .sql file. I would like to know which sql statment I have to use so that it update the "id_customer" value.

CodePudding user response:

Read the file into a second table and then use an update join:

UPDATE Soft_orders t1
INNER JOIN Table_From_File t2
    ON t2.id_order = t1.id_order
SET t1.id_customer = t2.id_customer;
  • Related