Hi Everyone,
How to get fist and last record from a table in oracle?
Thanks in advance
Answers were Sorted based on User's Feedback
Answer / rajesh venati
select * from table_name where rownum=1
union
select * from table_name where rowid=(select max(rowid) from
table_name);
| Is This Answer Correct ? | 27 Yes | 5 No |
Answer / rajesh venati
this will also work
select * from table_name where rowid=(select min(rowid) from
table_name)
union
select * from table_name where rowid=(select max(rowid) from
table_name);
| Is This Answer Correct ? | 23 Yes | 2 No |
Answer / chandana
select * from table_name
where rowid in ((select min(rowid) from table_name),
(select max(rowid) from table_name));
| Is This Answer Correct ? | 8 Yes | 0 No |
Answer / ramesh
Select * from table_name where rowid =(select min(rowid)
from tanle_name)
union
select * from table_name where rowid = (select max(rowid0
from table_name);
| Is This Answer Correct ? | 5 Yes | 2 No |
Answer / samr
use Northwind
go
select top(1) * from Orders
union
select * from orders where orderid =
(select MAX(OrderID) from Orders)
| Is This Answer Correct ? | 2 Yes | 2 No |
Answer / venkyhulk1
select *
from (select rownum r, e.* from emp e)
where r in ((select max(rownum) from (select rownum , e.*
from emp e)),(select min(rownum) from (select rownum , e.*
from emp e)))
this querry will get the first and last records of the table
with respect to the way the data is stored in the table
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ataullah
Select * from emp where rowid=(select max(rowid) from emp) or rowid=(select min(rowid) from emp)
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ashwani kumar singh
SELECT * FROM EMP WHERE ROWNUM < 2
UNION
SELECT * FROM (SELECT * FROM EMP ORDER BY EMPNO DESC )
WHERE ROWNUM < 2
| Is This Answer Correct ? | 1 Yes | 2 No |
Rownum and RowID displays the results faster than others -
select * from <Table_Name> where rownum=1
union
select * from (select * from <Table_Name> order by rownum desc) where rownum=1
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / gourav
select * from emp(table name)
where rownum = 1 and 30
this query will display the first and last record
for eg rownum start from 1 and rownum last record is 30..by
execute this query u wil get frst and last reord
| Is This Answer Correct ? | 0 Yes | 2 No |
How can we overcome recursive triggers in SQL?
What is linq to sql?
What is synchronized subquery?
Explain clause in sql?
Which are the most commonly used sql joins?
What are the basic sql commands?
What are the types pl/sql code blocks?
What can be a size of a pl/sql block? Is there any limit?
what are the limitations of mysql in comparison of oracle? Mysql vs. Oracle. : Sql dba
what is the command for user data type?
how to delete duplicate rows from a join tables(I have three tables on that join) how do you know which join is need to be used? The select statement I have is: SELECT gc_skill_type.skill_type, gc_area_tec.area, gc_technology.technology, gc_technology.id_technology, gc_area_tec.id_area_tec FROM gc_skill_type, gc_area_tec, gc_technology WHERE gc_area_tec.id_skill_type (+) = gc_skill_type.id_skill_type AND gc_technology.id_area_tec (+) = gc_area_tec.id_area_tec order by gc_skill_type.skill_type asc, gc_area_tec.area asc, gc_technology.technology asc
What is java sql drivermanager?
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)