0

In mysql database table I have integer field, what i want to find missing minimum value of the sequence.

Please Help.

1,2,3,5,6,8,....
missing is 4
Boni
  • 590
  • 1
  • 3
  • 11
  • Do you have an integer column, and you want the smallest integer that there is no row for OR do you have text column with comma separated integer? – jkj Jan 19 '12 at 07:35
  • Probably you want this: http://stackoverflow.com/questions/1312101/how-to-find-a-gap-in-running-counter-with-sql – Sergio Tulentsev Jan 19 '12 at 07:36

1 Answers1

4

You can do something like this:

SELECT  val + 1
FROM    mytable t1
WHERE   NOT EXISTS
        (SELECT NULL FROM mytable t2 WHERE t2.val = t1.val + 1)
ORDER BY val
LIMIT 1
Ted Hopp
  • 232,168
  • 48
  • 399
  • 521