Last active
August 29, 2015 14:09
-
-
Save mrclay/cb751a1e432ce21c4f68 to your computer and use it in GitHub Desktop.
Elgg: Delete entity rows where the associated secondary table rows no longer exist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELETE FROM elgg_entities | |
WHERE guid in ( | |
SELECT * FROM ( | |
SELECT e.guid FROM elgg_entities AS e | |
LEFT JOIN elgg_users_entity AS u ON (e.guid = u.guid) | |
WHERE e.type = 'user' | |
AND u.guid IS NULL | |
) AS q1 | |
UNION | |
SELECT * FROM ( | |
SELECT e.guid FROM elgg_entities AS e | |
LEFT JOIN elgg_objects_entity AS o ON (e.guid = o.guid) | |
WHERE e.type = 'object' | |
AND o.guid IS NULL | |
) AS q2 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment