how to retrieve last tree records from table?
select *from emp where rownum > (select count(*)-3 from
emp);
i am using this query to get last three records from table
but its not giving any output, so please tell me what is the
error in this query.

Answer Posted / ammu

Hi Prakash Kumar,

this is the problem with rownum. In general never use = or
> with rownum. I will explain the reason.

Siuppose u hav 2 rowns in a table.

when u say select * from emp where rownum =2.

then 2 row will get selected ...but as soon as it gets
selected..since it is the only row in the selection its row
num will change to 1.

so this will return 0 rows.

similarly..

when u say rownum >1
2 row will get selected but as soon as it get selected its
rownum changes to 1.. so no rows selected again

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is bdb (berkeleydb)? : Sql dba

751


What types of commands can be executed in sql*plus?

761


What is sap sql anywhere?

678


Enlist the advantages of sql.

739


What is type and rowtype in pl sql?

740






What are the different dml commands in sql?

759


How many primary keys can a table have?

718


Is and as keyword in pl sql?

684


What are different functions in sql?

685


Difference between global and parameter variables?

1653


What is the need of merge statement?

757


What is use of trigger?

675


What is auto increment feature in sql?

817


What is an inner join sql?

694


Do stored procedures prevent sql injection?

725