Merge Two Versions of A Table Together in a Database

(0 votes, average 0 out of 5)

When keeping multiple versions of a website, or perhaps migrating a website to a new environment, it is often necessary to merge any changes between the two databases. The databases have the same structure, but each has new, unique content which needs to be added to the other. The following tutorial uses syntax for MySQL, however it should be applicable to other major database schemas. The following example assumes that the master database where we want all of the changes to reside is called database1, and the table we want to merge is called mytable, The secondary database with the changes to be merged is called database2. This command can be executed from within phpMyAdmin or from the MySQL command line:

1
2
3
4
INSERT IGNORE
  INTO database1.mytable
SELECT *
  FROM database2.mytable

This will insert all of the new data from database2.mytable, while excluding any duplicates.

Partner Links:
 
Related Articles

» How to Use a Linux (or Mac OS X) Terminal

Every computer hobbyist, at some point, learns to use Linux.  The transition from using a UI based interface in Windows or Mac to performing many functions through the terminal can be a jarring experience for many people.  Many users find the terminal difficult to use and inferior to navigating a UI.  However, the Linux terminal is an extremely powerful device that many learn to love and use often.  Here is a basic introduction to get your feet wet with a terminal.  It...

» How to Get the Latest Version of a Program in Ubuntu

Ubuntu, the popular Linux distribution, is well-known for its stability. This stability is due in part to its 6-month release cycle. Main programs included with Ubuntu are only updated every 6 months. This ensures that the developers have adequate time to test the software for regressions, bugs, and instabilities. However, sometimes it is nice to install the latest version of a program. This tutorial will use the application launcher Kupfer (like Gnome Do or Launchy) but the same procedure...

» How to Count the Number of Files in a Directory in Linux

Counting the number of files in a directory from a Linux command line is easy.  The following command will return the number of files in the current directory and all subdirectories: $> find directory_name -type f -follow | wc -l  This will count all files and files in subdirectories, but not the subdirectories themselves.  To find all the files in only the current directory, you can use: $> find directory_name -type f -maxdepth 1 -follow | wc -l  If you would like to...