Skip to content

Instantly share code, notes, and snippets.

@mrclay
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrclay/cb751a1e432ce21c4f68 to your computer and use it in GitHub Desktop.
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
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