Re: sql - first 10 records
Posted in 1995
Paul Roberts — — source: Informix-list mailing list archive (1991-1998)
Here's one way to do it. If I want to select the "first 10" states from
my table "states", then this query:-
select al_1.state_code, al_1.state_name
from states al_1, states al_2
where al_1.state_code >= al_2.state_code
group by 1,2
having count(*) <= 10
order by 1
returns these data:
state_code state_name
AK ALASKA
AL ALABAMA
AR ARKANSAS
AZ ARIZONA
CA CALIFORNIA
CO COLORADO
CT CONNECTICUT
DC DISTRICT OF COLUMBIA
DE DELAWARE
FL FLORIDA
Note that "first 10" in this case is taken to refer to the sort sequence of
the state codes. And yes, I know that DC isn't a state....
- Paul