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

Merging Two Tables

forums forums SQLyog Using SQLyog Merging Two Tables

  • This topic is empty.
Viewing 2 reply threads
  • Author
    Posts
    • #9613
      w2k
      Member

      I have two tables (with identical structure) which I want to combine/merge. How should I do it?

      Actually these are two blogs of mine which I plan to merge. Only the itemid column needs to change.

    • #21217
      peterlaursen
      Participant

      The SQL 'UNION' clause is for this.

      Code:
      CREATE TABLE new_table SELECT * from old_table1 UNION SELECT * from old_table2;

      Note that if you have an autoincrement PK in old_tables the new table will not have a PK. You must then add it using ALTER TABLE. If there are dublicates you may need to drop the PK-column and recreate it.

    • #21218
      w2k
      Member

      Thanks Peter, I realised about the PK bit just as your postscript came in. It works like a breeze. Thanks a ton.

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