table :->CREATE TABLE COMPANY  ( ID INTEGER,NAME CHAR(50))……
replace N with the number you want

1.SELECT
    ID,    NAME
FROM
    COMPANY C1
WHERE
    ( N = (    SELECT
                COUNT ( DISTINCT ( C2.ID ) )
            FROM
                COMPANY C2
            WHERE
                C2.ID >=C1.ID
    )
    )

2. select T.ID,T.NAME from (
select ID,NAME,DENSE_RANK ()OVER (ORDER BY ID desc)  RK
FROM COMPANY) as T
where T.RK=N

Advertisements