I have some duplicated rows on my Wordpress wp_postmeta table. Actually hundreds of cases where old postmeta data are listed 2 or 3 times... maybe from some data import process done in the past... So I need to remove unneeded duplicate rows from wp_postmeta table, leaving just the ones with higher meta_id number... To exemplify what the wp_postmeta table looks like:
meta_id | post_id | meta_key | meta_value
155153 | 177115 | owner_img | https://www.example.com/a.jpg
176231 | 177115 | owner_img | https://www.example.com/a.jpg
193983 | 177115 | owner_img | https://www.example.com/a.jpg
Note that these are 3 metadata for the same post on wp_post table (as it has the same post_id)... so I just need to keep the latest metadata row, and delete all other instance where metadata is duplicated for each meta_key... how can I do that?
DELETE wp_postmeta.*
FROM wp_posts
INNER JOIN wp_postmeta ON wp_postmeta.post_ID = wp_posts.ID