Skip to content

Instantly share code, notes, and snippets.

View sdynamo's full-sized avatar

sDynamo sdynamo

View GitHub Profile
@sdynamo
sdynamo / gist:cc4e921184d53c62c1d9e2848157f7bd
Created June 20, 2017 13:47
Custom SQL to select and delete duplicate listing for Sabai Directory plugin. Based on address AND phone number.
-- Select query
SELECT pst.`post_id`, pst.`post_title`, pst.`post_slug`
FROM (
SELECT min(pst.`post_id`) AS `min_id`, dst.`post_title`, cnt.`phone`, loc.`address`, loc.`street`, loc.`city`, loc.`state`, loc.`zip`, loc.`country`, COUNT(*) AS `cnt`
FROM (SELECT DISTINCT `post_title`
FROM `tableprefix_sabai_content_post`
WHERE `post_entity_bundle_type` = 'directory_listing' AND
`post_slug` REGEXP '[[:digit:]]') dst JOIN `tableprefix_sabai_content_post` pst
ON dst.`post_title` = pst.`post_title`
JOIN `tableprefix_sabai_entity_field_directory_contact` cnt