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
define sql update statement ? : Sql dba
Show code of a cursor for loop.
how to do backup entire database? : Transact sql
How do I find sql profiler?
Is sql better than access?
What are local and global variables and their differences?
How to call a javascript function from pl sql?
Can you have more than one key in a database?
What steps server process has to take to execute an update statement?
What does trigger mean in slang?
how to use 'mysql' to run sql statements? : Sql dba
What is a sql schema used for?
What is data type in sql?
what are different types of collation sensitivity? : Sql dba
what is 'mysqldump'? : Sql dba