Skip to content

Instantly share code, notes, and snippets.

@Vladnev
Last active November 20, 2017 10:38
Show Gist options
  • Save Vladnev/ccdd8a6871474b0551f9c1b41c824ebb to your computer and use it in GitHub Desktop.
Save Vladnev/ccdd8a6871474b0551f9c1b41c824ebb to your computer and use it in GitHub Desktop.
SELECT f.id + 1 AS empty
FROM <table> f
LEFT OUTER JOIN <table> r ON f.id + 1 = r.id
WHERE r.id IS NULL
ORDER BY f.id
LIMIT 1;
SELECT f.id + 1 AS empty
FROM <table> f
WHERE (
SELECT 1
FROM <table> s
WHERE s.id = f.id + 1
) IS NULL
ORDER BY f.id
LIMIT 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment