Text Size
Thursday, November 26, 2015


Update one table and select from another using mysql

How to Update one table from an SQL statement from another table.

UPDATE `table1` a, `table2` b
SET a.`Field1`=b.`Field1`
WHERE a.`Field2`=b.`Field2`;

Field2 is the field your matching table1 and table2

Field1 is the field you want to update, you can add more field, just make sure to separate them by a coma `,`.


UPDATE `bid` b, `customers` c
SET b.`Region`=c.`Region`
WHERE b.`cutomer_id`=c.`id`;

This is only valid for MySQL.

Copyright © 2015 by Mike Zriel - Zriel.com