WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a simple way to merge two wp_posts tables while avoiding duplicates?

share|improve this question
Short answer: "Yes, that is possible." For an answer that also answers the implied "How?" you will need to supply more information. Where is the second table right now (in a file, in the same DB under a different name)? How do you plan on identifying "duplicates"? – Johannes Pille Mar 31 '13 at 11:29
The second DB is in a .sql file. I plan to identify duplicates with the 'post_content' field. – drake035 Mar 31 '13 at 13:02

Import the new table as wp_posts_2, then join them and delete all duplicates based on post_content; then merge the two tables.

The following SQL query (untested!) should give the posts from the new table to be deleted:

SELECT wp2.* FROM wp_posts_2 as wp2 LEFT JOIN wp_posts as wp ON wp2.post_content = wp.post_content WHERE wp2.post_content = wp.post_content

So, you can delete the entries with this query (also untested):

DELETE wp_posts_2.* LEFT JOIN wp_posts as wp ON wp_posts_2.post_content = wp.post_content WHERE wp_posts_2.post_content = wp.post_content

Then merge the two tables.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.