Mike
Mike

Reputation: 2900

MySQL to update a table with information from another table

I can only explain this with an example.

I have 2 tables (table1 and table2) which each contain fielda fieldb fieldc and fieldd.

I want to

UPDATE table2 
SET    table2.fieldc = table1.fieldc, 
       table2.fieldd = table1.fieldd 
WHERE  table2.fielda = table1.fielda 
       AND table2.fieldb = table1.fieldb 

Upvotes: 0

Views: 34

Answers (1)

Raphaël Althaus
Raphaël Althaus

Reputation: 60493

You just miss "table1" declaration

update table2, table1
...

other version

UPDATE table2
JOIN table1 
  ON table2.fielda = table1.fielda 
       AND table2.fieldb = table1.fieldb 
SET    table2.fieldc = table1.fieldc, 
       table2.fieldd = table1.fieldd 

Upvotes: 4

Related Questions