Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MYSQL - UPDATE multiple rows from another table

I have 2 tables. one from yesterday (300k rows) and another one from today with the same count of rows but the data changes in some columns.

Those two tables have around 120 columns.

How can i update only the changes.
I have tried using delete :

   delete from tableA
   where id in (select id from tableB)

But it too slow.
Also tried

   update tableA inner join tableB
   on tableA.id=TableB.id

And it didn't worked.

enter image description here

like image 229
Katy Avatar asked Sep 05 '25 03:09

Katy


1 Answers

You have to set the values in your update query to get the changes.

Example:

update tableA inner join tableB on tableA.id=TableB.id
set tableA.col1=TableB.col1,
    tableA.col2=TableB.col2,
    tableA.col3=TableB.col3;

and also you can add more conditions in where clause to make query run on filtered records.

like image 54
Abhishek Ginani Avatar answered Sep 07 '25 17:09

Abhishek Ginani