Unsupported Screen Size: The viewport size is too small for the theme to render properly.

Merge Tables

forums forums SQLyog Using SQLyog Merge Tables

  • This topic is empty.
Viewing 3 reply threads
  • Author
    Posts
    • #12618
      dirk mauroo
      Member

      Hoi,

      What is the easiest way to merge tables in the same database ?

      Thanks

      Dirk

    • #33195
      Larry Woods
      Member

      This should do it:

      INSERT INTO table1 SELECT * FROM table2;

      This would add the records from table2 into (append) table1 ASSUMING the same schema for both tables.

      Larry Woods

      'dirk wrote:

      Hoi,

      What is the easiest way to merge tables in the same database ?

      Thanks

      Dirk

    • #33196
      ashwin
      Member

      Addition to Larry Woods SQL query, you need to consider these-

      INSERT IGNORE INTO table1

      SELECT * FROM table2;

      which allows those rows in table1 to supersede those in table2 that have a matching primary key, while still inserting rows with new primary keys.

      Refer MySQL docs: http://dev.mysql.com/doc/refman/5.5/en/insert-select.html

      Alternatively,

      REPLACE INTO table1

      SELECT * FROM table2;

      will update those rows already in table1 with the corresponding row from table2, while inserting rows with new primary keys.

      Refer: http://dev.mysql.com/doc/refman/5.5/en/replace.html

    • #33197
      peterlaursen
      Participant

      or “INSERT INTO .. ON DUPLICATE KEY …”. Point is that if you have Primary/unique Keys in the tables you will need to handle the conflict somehow.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.