SQL - Update Select (Update a Table Based on Values in another Table)

A simple and quick snippet of SQL to update table values based on the values stored in another table — in other words, UPDATE SELECT. This code has only been tested in MySQL, similar code may be used in MSSQL or other database engines which I will try and add later.

UPDATE SELECT using JOIN Model:


UPDATE Dest
SET    Dest.Address1 = Src.Address1,
       Dest.Address2 = Src.Address2
FROM   SourceTableName Src
JOIN   DestinationTableName Dest ON Dest.PersonID = Src.PersonID



UPDATE SELECT using WHERE Model:


UPDATE DestinationTableName Dest, SourceTableName Src
SET    Dest.Address1 = Src.Address1,
       Dest.Address2 = Src.Address2
WHERE  Dest.PersonID = Src.PersonID

Multiple tables deletion in Mysql using wildcards

I've found some solution on mysql website, how to delete multiple tables according to some condition, you will need it when you will want delete specific tables from your DB.



( Read more )