Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to find the missing number by sql
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00687629
Message ID:
00687648
Views:
29
This message has been marked as a message which has helped to the initial question of the thread.
AKhan,

Although I did not fully tested it, I think this should work (I am usually wrong thou!)
create cursor c_test (value I)
insert into c_test values (2)
insert into c_test values (3)
insert into c_test values (4)
insert into c_test values (6)
insert into c_test values (7)
insert into c_test values (12)
insert into c_test values (13)
insert into c_test values (14)
insert into c_test values (16)
insert into c_test values (17)
select	value-1 as value ;
	from	c_test ;
	where 	value not in (select value+1 from c_test) and value-1 > 0 ;
	into 	cursor c_result
If you are only interested in the first missing number, then you can add:
	order by value ;
	top 1
or for the last one:
	order by value descending;
	top 1
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform