Last active
August 29, 2015 14:18
-
-
Save mattwells/fe4c3fd19e323a9b86fa to your computer and use it in GitHub Desktop.
Fast query to find orphaned rows
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
SELECT `id`, COUNT(`id`) as `count` | |
FROM ( | |
SELECT `id` | |
FROM `items` | |
UNION ALL | |
SELECT `id` | |
FROM `related` | |
) AS `union` | |
GROUP BY `id` | |
HAVING `count` = 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment