Text Size
Saturday, July 26, 2014

08.01.13

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 `,`.

Example:

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

This is only valid for MySQL.

Add comment


Security code
Refresh

Copyright © 2014 by Mike Zriel - Zriel.com