On Thu, 8 Mar 2007 11:13:03 -0800, Meg Brady <Meg
I'm trying to write a query that finds a missing number in a sequence, when I
don't know how many numbers are in the sequence. Anybody have any ideas?
A Self Join will work:
SELECT A.numberfield+1 AS Missing
FROM yourtable AS A
LEFT JOIN yourtable AS B
ON B.numberfield = A.numberfield + 1
WHERE B.numberfield IS NULL;
This will show the first missing value in any block of missing values; of
course you'll always get at least one hit, the infinitely large gap after the
largest value in the table.
John W. Vinson [MVP]