user3713233
user3713233

Reputation: 3

Update MySQL Large table with another table's data

I have Two Tables in same database, Table 1 contains approx 4 million records and table 2 has 100K

Table 1 look like

id      | Balance
-----------------
234344  | 4.3
232434  | 4.3
243244  | 4.3
232443  | 4.3
100001  | 2.3
100002  | 2.3
100003  | 2.3
100004  | 2.3
100005  | 2.3

Table 2

id      | Balance
-----------------
234344  | 11.555
232434  | 12.32
243244  | 1.0
232443  | 2.6

I need to copy the value of Balance from Table 2 to Table 1 based on check ID in each table

Tips for this UPDATE statement ? and please note that tables are too big

need faster solution

Upvotes: 0

Views: 182

Answers (1)

craig1231
craig1231

Reputation: 3877

Ensure the id fields in both tables are indexed. This will greatly aid the next query below

UPDATE table1 JOIN table2 ON table2.id = table1.id SET table1.Balance = table2.Balance

Please dont forget if this helps to accept the answer :)

Upvotes: 3

Related Questions