Possible Duplicate:
Find missing values
How do I get first unused ID in the table?
myTable
-----+---------
ID | Value
-----+---------
7 | Foo
9 | Bar
19 | Etc
I need to do a query here to get the missing ID (number 1), the result will be only the first row (result), maybe using LIMIT 1
, and then insert using this ID. So, it will look this:
myTable
-----+---------
ID | Value
-----+---------
1 | Fir
7 | Foo
9 | Bar
19 | Etc
Now on the next query it will result only the number 2.
Notes:
- I am using MySQL 5.1.32