I need to find missing number from column, serial number always start with FAC-number. below is screenshow enter image description here
I have table more than 100k Records in Tables and I want to find missing serial number.
Expecting Results of above table is :
FAC-00002
There are many records in table so, I wanted that to be more quicker result. Any help would be appreciated.
2
Answers
If only individual serial numbers were missing, you could try to use the window function
LAG
. For the more general case (with multiple consecutive serial numbers missing), you can use/generate the full list of permitted values. Via anOUTER
join, you get the missing values.You will probably need to adjust the maximum recursion depth.
See it in action: DB-Fiddle
Please comment, if and as this requires adjustment / further detail.
you can use a query like this to find the first missing item.
sample