× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hello Richard

Thank you very much. That did the job.

Best regards

Jan


Am 01.12.2015 um 11:09 schrieb Richard Casey:
Try this.


For the lowest missing number:

select a.number+1
from numbers a
exception join numbers b on a.number+1=b.number
order by a.number+1
fetch first row only

The exception join gives you any number N where the file does not also
contain N+1.
The lowest of those numbers is one less than the lowest missing number.


For the highest missing number:

select a.number-1
from numbers a
exception join numbers b on a.number-1=b.number
order by a.number-1 desc
fetch first row only

This exception join gives you any number N where the file does not also
contain N-1.
The highest of those numbers is one more than the highest missing number.

That was fun. Hope it helps!
Richard

-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Jan
Grove Vejlstrup
Sent: Tuesday, December 01, 2015 4:33 AM
To: Midrange Systems Technical Discussion
Subject: SQL - Question

Hello,

I have a file with one field:

1
2
4
5
6
8
9

Is it possible with SQL to get the lowest number *not* in the file, here 3?
Or the highest, here 7.

Best regards

Jan

--




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.