Re: sql - first 10 records
Posted in 1995
>
> Any ideas on how to get the first 10 records of a table/rec using only sql/isql.
> table a
> -no-----
> 1
. . . .
>
> 1)can't use 10 + first no - may be gaps in numbering
> 2)can't use 10 + first rowid - may be gaps in numbering
> Any ideas.
> Thanks.
> Bob
Bob,
This might not be too nice but in case you do not get other responses,
this is what worked for me. I tried it for the first four (and added more
logic for the first five) so if you keep adding logic the same way you
might get the firts ten:
SELECT num
FROM table t1
WHERE t1.num >=
(SELECT MAX(t2.num)
FROM table t2
WHERE t2.num NOT IN
(SELECT MAX(t3.num)
FROM table t3
WHERE t3.num NOT IN
(SELECT MAX(t4.num)
FROM table t4
WHERE t4.num <> t2.num
AND t4.num NOT IN
(SELECT MAX(t5.num)
FROM table t5
WHERE t5.num <> t2.num
AND t5.num <> t3.num
AND t5.num NOT IN
(SELECT MAX(t6.num)
FROM table t6
WHERE t6.num <> t2.num
AND t6.num <> t3.num
AND t6.num <> t4.num
)
)
)
)
)
ORDER BY 1
Best regards,
Jose Antonio
--
*SUPERINTENDENCIA NACIONAL DE ADMINISTRACION TRIBUTARIA (SUNAT) LIMA - PERU*
*CENTRO INTERAMERICANO DE ADMINISTRADORES TRIBUTARIOS / Conv. SUNAT-BID-CIAT*
Jose Antonio Robles F. E-mail: joser@sunat.gob.pe
*******If you know about AFS Intercultural Programs, Please e-mail me.*******