While this line is not necessary it’s a good idea to limit to this initially until you are ready to run on a larger scale.
AND data1 LIKE "%<Organization Name>%"
SELECT _id ,raw_contact_id ,data1 ,data4 ,data5 FROM data WHERE mimetype_id IN ( SELECT _id FROM mimetypes WHERE mimetype LIKE "%organization%" ) AND data1 LIKE "%<Organization Name>%" AND raw_contact_id IN ( SELECT raw_contact_id FROM data WHERE mimetype_id IN ( SELECT _id FROM mimetypes WHERE mimetype LIKE "%organization%" ) GROUP BY raw_contact_id HAVING count(raw_contact_id) > 1 );
DELETE FROM data WHERE _id IN ( SELECT max(_id) AS _id FROM data WHERE data1 LIKE "%<Organization Name>%" AND raw_contact_id IN ( SELECT raw_contact_id FROM data WHERE mimetype_id IN ( SELECT _id FROM mimetypes WHERE mimetype LIKE "%organization%" ) GROUP BY raw_contact_id HAVING count(raw_contact_id) > 1 ) );
Last Updated on October 26, 2015