I'm using the following query to display duplicate entries in my database (looks like I've accidentally run the script twice, though it may have been more as it may have been a malicious user).
I'm using the following query, though it doesn't actually satisfy my requirements:
SELECT meta_value, COUNT(meta_value) AS cnt
FROM wp_postmeta
GROUP BY meta_value
HAVING cnt > 1
ORDER BY cnt;
I'd also like the query to check if the duplicate entries have the same post_id
and meta_key
.
So, for example:
meta_id post_id meta_key meta_value
1 10 size large
2 10 colour blue
3 10 size large
4 11 size large
meta_id
1 and 3 are duplicate entries.
I would like to delete ALL BUT ONE of such entries.
Is there a way of doing this with a single query? If I could view the rows first to ensure that the query does as expected, that would be great.
Thanks in advance,