V
V
Vlad Avtomat2018-11-01 19:00:52
MySQL
Vlad Avtomat, 2018-11-01 19:00:52

How to find out with one request a number that is missing 1 or more between the digits?

For example, there is a table with records
id|position
1|1
2|2
3|3
4|6
5|7
6|8
7|9
How can I get position 4 using a query? How to find out that the 4th position is free.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2018-11-01
@tsklab

If ID is an auto-primary key, then you need to make a separate "number" field. Today you need no passes, and tomorrow start counting the first day of the month.
If there are few records, it is also possible to search. Or a separate table of unoccupied numbers.
But if you just answer the question:

select top 1 ID from table where ID<>POSITION order by ID

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question