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

  • 2
    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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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