Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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



Hi Everyone, How to get fist and last record from a table in oracle? Thanks in advance..

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

Hi Everyone, How to get fist and last record from a table in oracle? Thanks in advance..

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

Hi Everyone, How to get fist and last record from a table in oracle? Thanks in advance..

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

Hi Everyone, How to get fist and last record from a table in oracle? Thanks in advance..

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

Hi Everyone, How to get fist and last record from a table in oracle? Thanks in advance..

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

Hi Everyone, How to get fist and last record from a table in oracle? Thanks in advance..

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

Hi Everyone, How to get fist and last record from a table in oracle? Thanks in advance..

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

Hi Everyone, How to get fist and last record from a table in oracle? Thanks in advance..

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

Hi Everyone, How to get fist and last record from a table in oracle? Thanks in advance..

Answer / nitinmukhraiya

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

Hi Everyone, How to get fist and last record from a table in oracle? Thanks in advance..

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

Post New Answer

More SQL PLSQL Interview Questions

what are the differences between binary and varbinary? : Sql dba

0 Answers  


From an Employee table, how will you display the record which has a maximum salary?

29 Answers   Cap Gemini, Exilant, Synechron,


What is sharding in sql?

0 Answers  


using cursors salesman get bonus as 10% of their salary , managers get 20% , analalist get 30%. generae a report showing the employee name, salary , bonus.

4 Answers   Fidelity,


How do I count duplicates in sql?

0 Answers  


How is data stored on a disk?

0 Answers  


what is the difference between granting and creating a view?

2 Answers  


What is sql*loader?

0 Answers  


What does <> sql mean?

0 Answers  


Store procedure will return a value?

4 Answers   eMids,


What are the different types of functions in sql?

0 Answers  


What is sql profiling in oracle?

0 Answers  


Categories