SQL script to remove dups


Job Description

we are using job manager plugin in a wordpress to store resumes and applicants.And we have tons of duplicate records. The plugin creates a record in wp_post table and wp_postsmeta table. WP_POSTS is a primary key, and then used as a foreign key in a wp_postmeta. To find duplicates I run this query:
SELECT a.meta_value,
COUNT(a.meta_value) AS NumOccurrences
FROM wp_postmeta a
where a.`meta_key` = "data4"
and a.post_id in (select id from wp_posts where post_title = "Application" and post_type = "jobman_app")
GROUP BY a.meta_value
HAVING ( COUNT(a.meta_value) > 1) ORDER BY `NumOccurrences` ASC

I need to delete all records, except one

Other open jobs by this client