Selasa, 03 Juni 2014

Update column in a table whose values are not found in another table. in MySQL

Update column in a table whose values are not found in another table.

UPDATE TABLE_1 LEFT JOIN TABLE_2 ON TABLE_1.COLUMN_1= TABLE_2.COLUMN_2
SET TABLE_1.COLUMN = EXPR WHERE TABLE_2.COLUMN2 IS NULL

An outerjoin is performed based on the equijoin condition.
Records not matching the equijoin from table2 are marked with null.

This facilitates to update table1 column with expression whose corresponding value from table2 is returned as NULL

UPDATE tblpoksi as a
inner join tblunit as b ON(a.kodeunit=b.kodeunit)
SET a.idUnit=b.idUnit 

Tidak ada komentar:

Posting Komentar