I am working on an application that has to assign numeric codes to elements. This codes are not consecutives and my idea is not to insert them in the data base until have the related element, but i would like to find, in a sql matter, the not assigned codes and i dont know how to do it.
Any ideas? Thanks!!!
Edit 1
The table can be so simple:
code | element ----------------- 3 | three 7 | seven 2 | two
And I would like something like this: 1, 4, 5, 6. Without any other table.
Edit 2
Thanks for the feedback, your answers have been very helpful.
This will return
NULLif a code is not assigned:This will return all non-assigned codes:
There is no pure
SQLway to do exactly the thing you want.In
Oracle, you can do the following:In
PostgreSQL, you can do the following: