Gaps in Data [message #38785] |
Tue, 14 May 2002 21:44 |
selvi
Messages: 2 Registered: May 2002
|
Junior Member |
|
|
Hi. I need to write a select statement which will tell me whether the data in a table is in sequence.
e.g.,
TableA
1
2
4
5
6
The select statement should tell me that the data in TableA is not in sequence. Thanks.
|
|
|
|
Re: Gaps in Data [message #38801 is a reply to message #38785] |
Wed, 15 May 2002 23:35 |
|
Maaher
Messages: 7065 Registered: December 2001
|
Senior Member |
|
|
thanks Rick! It is a simple, yet beautiful solution. It is nice to see that there are still some people awake! I can't believe I looked over this simple solution!
If you issue the following Select, you'll get the numbers that are missing in the sequence:
===================
SQL> select * from mhe_test
2 /
COL_1
----------
1
2
4
5
7
SQL> SELECT (col_1+1) miss
2 FROM mhe_test a
3 WHERE NOT EXISTS (SELECT 1
4 FROM mhe_test b
5 WHERE b.col_1 = a.col_1+1
6 )
7 AND a.col_1 != (SELECT MAX(col_1)
8 FROM mhe_test
9 )
10 /
MISS
----------
3
6
SQL>
===================
HTH,
MHE
|
|
|