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.
Answers were Sorted based on User's Feedback
Answer / ajit nayak
select *from emp
minus
select *
from emp
where rownum <= (select count(*)-3 from
emp);
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / swastik
SELECT * FROM
(
SELECT * FROM Emp
ORDER BY ROWNUM DESC
)
WHERE ROWNUM <= 3;
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ashwin
if emp table is having 10 records then
1)for first 6 write
select ename,sal from(select ename,sal from emp order by sal
desc) where rownum <7;
2)for last 3 write
select ename,sal from(select ename,sal from emp order by sal
desc) where rownum >7;
Is This Answer Correct ? | 2 Yes | 3 No |
Answer / shekaran04
Hi,
First thing you cannot use " ROWNUM > (somthing) "
And to get last three records...
Select *from emp
minus
Select *from emp where rownum <(select Count(*) from emp)-
3;
Good Luck...
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / mohammed shahid
select distinct TOP3 from emp order by rownum desc;
Is This Answer Correct ? | 2 Yes | 8 No |
Is it possible to remove child records without removing master table records...the two having pk,fk relationship?
What is linq to sql?
How to assign sql query results to pl sql variables?
Can we insert data in view?
What is the difference between truncate and drop statements?
what is rdbms? : Sql dba
What is sql prepared statement?
what is text? : Sql dba
Describe the Index, Types of index, At what situation we have used? Which one s better than others?
Does sap use sql?
explain the options of myisamchk to improve the performance of a table. : Sql dba
how can we transpose a table using sql (changing rows to column or vice-versa) ? : Sql dba