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
How do I restart sql?
Explain the methods used to protect source code of pl/sql.
What is having clause in sql?
explain commit and rollback in mysql : sql dba
What are two statement types in sql?
Is sql difficult?
What is a nested table in word?
When do we use triggers?
What is primary key in db?
How many clustered indexes can you have?
How to return multiple rows from the stored procedure?
What is the mutating table and constraining table?
What is example of database?
Explain constraints in sql?
What is keys and its types?