Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

So I have a table with an int valued column, which has values between 0 and 43 (both included)

I would like a query that returns the min value of the range [0,44) which is not in the table.

For example, if the table contains: 3,5, 14. The query should return 0 if the table contains: 0,1, 14. The query should return 2 if the table contains: 0,3, 14. The query should return 1

if the table contains all values, the query should return empty.

how can I achieve that?

share|improve this question
Could you provide reason why for example 3,5,14 would yield 0 and 0,1,14 would yield 2? Your example is not that clear to me. – Edper 6 mins ago
@Edper As far as I understood he needs the lowest value which is not in the table. 0 is the minumum but in the second sequence 0 and 1 are present so 2 will be the lowest value not in the column. – Matteo 26 secs ago
add comment (requires an account with 50 reputation)

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.