Search code examples
sqloracle-databaseoracle10gtop-n

how to get latest 'n' updated row from a table


Possible Duplicate:
Oracle SQL - How to Retrieve highest 5 values of a column

i have a table abc, where i have following columns

act_id,cust_id,lastUpdatedDate,custActivity. Where act_id is primary key .

lastUpdatedDate store last activity done for this customer.

i am trying to get latest 10 rows for given custid based on lastUpdatedDate.

How can i achieve it.

-vivek


Solution

  • You can use ROWNUM in Oracle.. Click Here for Documentation

    select *
    from  
       ( select * 
         from your_table 
         where cust_id=<given cust_id>
         order by lastUpdatedDate desc ) 
    where ROWNUM <= 10;