Skip to content

Instantly share code, notes, and snippets.

@nkgokul
Created June 28, 2016 11:04
Show Gist options
  • Save nkgokul/1fc9ea7b2d16f1063cf24976b3cce958 to your computer and use it in GitHub Desktop.
Save nkgokul/1fc9ea7b2d16f1063cf24976b3cce958 to your computer and use it in GitHub Desktop.
Missing nids from node table
SELECT (t1.nid + 1) as gap_starts_at,
(SELECT MIN(t3.nid) -1 FROM node t3 WHERE t3.nid > t1.nid) as gap_ends_at
FROM node t1
WHERE NOT EXISTS (SELECT t2.nid FROM node t2 WHERE t2.nid = t1.nid + 1)
HAVING gap_ends_at IS NOT NULL
@nkgokul
Copy link
Author

nkgokul commented Jul 10, 2016

For users

SELECT (t1.uid + 1) as gap_starts_at,
(SELECT MIN(t3.uid) -1 FROM users t3 WHERE t3.uid > t1.uid) as gap_ends_at
FROM users t1
WHERE NOT EXISTS (SELECT t2.uid FROM users t2 WHERE t2.uid = t1.uid + 1)
HAVING gap_ends_at IS NOT NULL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment