I've got a Wordpress site with MySQL and I've would up with a lot of duplicate data due to a poorly written plugin that imports data into this site. I've fixed the plugin, and I am not working on getting rid of the duplicate data. Due to there being millions of dupes, I've decided to INSERT data into a new table rather than DELETE. I've been able to INSERT all of the data without duplicates but I don't know how to structure a query to avoid pulling in duplicates.
See the below example data. There are 3 "charge_0" lines per post ID, but there should only be one. How can I select the first 'charge_0' per unique post_id?
| meta id | post_id | meta_key | meta_value |
|---|---|---|---|
| 24 | 15 | charge_0 | 1000 |
| 25 | 15 | charge_0 | 1000 |
| 26 | 15 | charge_0 | 1000 |
| 27 | 16 | charge_0 | 3000 |
| 28 | 16 | charge_0 | 3000 |
| 29 | 16 | charge_0 | 3000 |
I haven't tried anything yet. I spent a few hours researching and I'm am lost. It seems like maybe I group by post ID but I am not sure. I'm a frontend dev by trade and this is a bit too far out of my comfort zone.