i have a select query that check for duplicates.
select ID, post_id, post_name, post_date, Count(meta_value) FROM wp_yepf_posts p join wp_yepf_postmeta pm on p.ID = pm.post_id WHERE p.post_type = 'product' and pm.meta_key='_sku' group by meta_value having count(meta_value)>1
this returns 2458 records with count(meta_value) greater than 1-- i need to delete these records (leaving one copy of the record if possible) but everytime i try a delete query like this i get an error
delete p
FROM wp_yepf_posts p
join wp_yepf_postmeta pm on p.ID = pm.post_id (select DUPLICATE.entity_id in (Select DISTINCT(pm.meta_key='_sku') as sku, Count(pm.meta_key='_sku') as skuCount, entity_id
from wp_yepf_posts p join wp_yepf_postmeta pm on p.ID = pm.post_id
group by sku Having skucount>1) as dup)
error is
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select DUPLICATE.entity_id in (Select DISTINCT(pm.meta_key='_sku') as sku, Count' at line 1