Find mininum unused value in mysql table

Posted by splattru on Stack Overflow See other posts from Stack Overflow or by splattru
Published on 2011-06-24T07:21:12Z Indexed on 2011/06/24 8:22 UTC
Read the original article Hit count: 181

Filed under:
|
|

I have a MySQL table like this:

+--------+-------+
+ Server + Port  +
+--------+-------+
+ 1      + 27001 +
+--------+-------+
+ 2      + 27002 +
+--------+-------+
+ 4      + 27004 +
+--------+-------+

How you can see - here was 27003 port - but it was deleted some time ago (just for example).

Is there some way to know the minimum value that is not used (higher than 27000 for example) in mysql table? Or there is no way and I need to make an separate table with all ports and column with "used" or "not used" ?

Situation explanation: I am creating game hosting website, and I can use auto-increment for ports, but I will have a lot of deleted/unused ports after some time, and I want to use all of them before increasing port range.

Thanks for your answers!

© Stack Overflow or respective owner

Related posts about mysql

Related posts about table