Updating multiple tables

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Updating multiple tables

Post by Benjamin »

Is there a way to perform an update on more than 1 table at a time? Something similar to a JOIN?

Code: Select all

update tableOne set tableOne.this=blah, tableTwo.that=blah
    join tabletwo on tableOne.x = tableTwo.x
    where tableOne.id = 5
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Post by GM »

Yes:

Code: Select all

UPDATE table_one a, table_two b 
SET a.field1 = 'value',
b.field1 = 'value'
WHERE a.id = 'this'
AND b.id = 'that';
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Thank you!!
Post Reply