Saturday, October 1, 2011

How to Merge Tables

This is an example of how to insert all the missing rows from one table, tbl_backup, into another table, tbl_target. Since the primary_key is auto incremented, we will use col2 and col3 to identify unique rows.

  SELECT * FROM `tbl_backup` AS bkup
  WHERE ROW(bkup.col1, bkup.col2) NOT IN
    (SELECT orig.col1, orig.col2 FROM `tbl_target` AS orig);

No comments:

Post a Comment