Write a query to get last 10 records from the table.
Answers were Sorted based on User's Feedback
Answer / jprakash025
select * from emp
minus
select * from emp
where
rownum<=(select count(*)-10 from emp);
or
SQL> select * from
2 (select rownum a, emp.* from emp)
3 where
4 a>(select max(rownum)-10 from emp);
| Is This Answer Correct ? | 24 Yes | 2 No |
Answer / l meher
select * from emp minus select * from emp where rownum<=
(select count(*)-10 from emp);
| Is This Answer Correct ? | 8 Yes | 3 No |
Answer / praveen biradar
select empno from (select empno from emp order by empno
desc) where rownum<=10 order by empno
| Is This Answer Correct ? | 10 Yes | 6 No |
Answer / pallavi v
with temp as
(select * from emp order by rownum desc)
select * from temp where rownum < = 10
| Is This Answer Correct ? | 0 Yes | 0 No |
select * from <TN>
minus
select * from <TN>
where
rownum <= (select count(*) - &n from <TN>)
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / nzabin
select PO_header_id from (select PO_header_id from PO_HEADERS_ALL order by PO_header_id
desc) where rownum <=10 order by PO_header_id;
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sudhir
select rownum, p.*
from (select * from <table name> order by param_cd desc) p
where rownum <= 10 ;
| Is This Answer Correct ? | 1 Yes | 2 No |
Answer / akshaya
select * from last10
minus
select * from last10
where row >= (select COUNT(*)-10 from last10)
condition should be >= not <=
for all the above queries
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / swastik
SELECT ROWNUM, E1.*
FROM
(
SELECT * FROM Emp
ORDER BY ROWNUM DESC
)E1
WHERE ROWNUM <= 10
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / chandrakishan
select * from emp where rownum>=
(select count(*)-10 from emp);
| Is This Answer Correct ? | 1 Yes | 3 No |
How is indexing done in search engines?
What are all the different normalizations?
how do you login to mysql using unix shell? : Sql dba
What is a subquery in sql?
What is the difference between delete and truncate commands?
what are the different tables present in mysql? : Sql dba
How can the performance of a trigger be improved?
Which is better varchar or nvarchar?
what are dynamic queries in t-sql? : Transact sql
What do you understand by case manipulation functions?
How to call shell script from pl sql procedure?
How do you modify a table in sql?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)