You didn't mention what DB you are using, but if it were Oracle, I would do
something like this ...
SELECT MIN (user_id) + 1
FROM user_table a
WHERE userid >= 3000
AND NOT EXISTS (
SELECT 0
FROM user_table b
WHERE b.user_id = a.user_id + 1)
You would obviously want to ensure there is an index on the user_id column
if the table has a lot of rows.
HTH,
Steve
-----Original Message-----
From: NIPP, SCOTT V (SBCSI) [mailto:[EMAIL PROTECTED]
Sent: Wednesday, 15 September 2004 5:31 AM
To: [EMAIL PROTECTED]
Subject: SQL question: Find next unused number...
I have a table that has a list of users with numeric user IDs.
The user IDs are not sequential. There are large gaps in the list of
numeric IDs. I want to pick the next unused number beginning at 3000.
How do I do this?
Thanks in advance.
Scott Nipp
Phone: (214) 858-1289
E-mail: [EMAIL PROTECTED]
Web: http:\\ldsa.sbcld.sbc.com