• Resolved morissaflo

    (@morissaflo)


    Hello,
    due some errors in product duplicating when product contain some custom postmeta fields now I have some products with a lot of repeated similar rows for same product.

    I need to clear wp_postmeta table but have very few MySQL knowledge. Could any one help how can I make it via phpmyAdmin?

    The table rows that I want to clean look like:

    [meta_id] [post_id] [meta_key] [meta_value]
    [1111111] [9999999] [_wpbcode] [css……]
    [2222222] [9999999] [_wpbcode] [css……]
    [3333333] [9999999] [_wpbcode] [css……]
    [4444444] [9999999] [_wpbcode] [css……]
    [5555555] [9999999] [_wpbcode] [css……]

    So these rows are different by meta_id only. I need to find all these rows which are have SAME post_id SAME meta_key and SAME meta_value simultaneously and drop all these rows except one single line. These row are absolutely identical. Will be remaining row has highest meta_id or lowest is not important.

    Thanks in advance!

Viewing 1 replies (of 1 total)
  • Thread Starter morissaflo

    (@morissaflo)

    Hello, I found the solution:

    CREATE TABLE wp_postmeta_new SELECT max(meta_id) meta_id from wp_postmeta GROUP BY post_id, meta_key, meta_value;
    DELETE from wp_postmeta WHERE meta_id NOT IN (select meta_id from wp_postmeta_new);

Viewing 1 replies (of 1 total)
  • The topic ‘How to clean wp_postmeta from duplicated rows for same post_id’ is closed to new replies.