bbPress Data Merge? or Join?

48 Views Asked by At

I am a Front End Web Developer with a question regarding the merge or joining of a database table. It's rather foreign to me and I want to make sure I am taking the best steps to achieve.

I have a website with bbpress (Wordpress Forum) data from X to June 7, 2020. I also have another bbpress instance of data from June 8, 2020 to present.

What would be the best method of "merging" -- keeping all data, removing duplicates, appending newest data onto old -- the two tables within these 2 Wordpress database tables?

What requirements might I need to ensure that I have from both?

Thank you!

Sample Data:

New/Up-to-date Database - Posts Table:

ID  post_author post_date       post_date_gmt   post_content    post_title  post_excerpt    post_status comment_status  ping_status post_password   post_name   to_ping pinged  post_modified   post_modified_gmt   post_content_filtered   post_parent guid    menu_order  post_type   post_mime_type  comment_count
144028  83  6/9/20 9:47:37 AM   2020-06-09 13:47:37 Body of post is here            publish closed  closed      144028          2020-06-09 09:47:37 2020-06-09 13:47:37     143020  domain.com/forums/reply/144028/ 3   reply       0
144027  12070   6/9/20 9:44:04 AM   2020-06-09 13:44:04 Body of post is here            publish closed  closed                                                  

Old Database - Posts Table:

ID  post_author post_date       post_date_gmt   post_content    post_title  post_excerpt    post_status comment_status  ping_status post_password   post_name   to_ping pinged  post_modified   post_modified_gmt   post_content_filtered   post_parent guid    menu_order  post_type   post_mime_type  comment_count
144028  83  2020-06-07 09:47:37 2020-06-07 13:47:37 Body of post is here            publish closed  closed      144028          2020-06-07 09:47:37 2020-06-07 13:47:37     143020  domain.com/forums/reply/144028/ 3   reply       0
144027  12070   2020-06-07 09:44:04 2020-06-07 13:44:04 Body of post is here            publish closed  closed                                                  

I have data in one database from X date to June 7, and another database from June 8 to present. I need to bring the two datasets together to bridge the gap.

Expected Result: All forums posts from X-date until present in the same database.

Thanks for help!

Edit: Add data sample and expected result.

1

There are 1 best solutions below

0
ScaisEdge On

Assuming your tables have the same table name but are in two separated database on the same mysql server then you could use

UNION for get a single result from both the tables with distinct (not result duplicated results) rows or UNION ALL for get also duplicated rows

    SELECT ID
        , post_author
        , post_date
        , post_date_gmt
        , post_content
        , post_title
        ....
        ....
        , post_mime_type
        , comment_count
    FROM new_database.Posts 
    UNION 
    SELECT ID
        , post_author
        , post_date
        , post_date_gmt
        , post_content
        , post_title
        ....
        ....
        , post_mime_type
        , comment_count
    FROM old_database.Posts