Last active
September 26, 2016 17:02
-
-
Save zippaaa/b0e90d481ddc0ca5440c7a2a5700ec43 to your computer and use it in GitHub Desktop.
MySql: First Available Id
This file contains hidden or 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 p.page_id + 1 AS FirstAvailableId | |
| FROM pages p | |
| LEFT JOIN pages p1 ON p1.page_id = p.page_id + 1 | |
| WHERE p1.page_id IS NULL | |
| ORDER BY p.page_id | |
| LIMIT 0, 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment