how to retrieve 1st and last row of table without using
group functions??

Answers were Sorted based on User's Feedback



how to retrieve 1st and last row of table without using group functions??..

Answer / prabhudatta

SELECT * FROM (SELECT * FROM EMP ORDER BY EMP_NO) WHERE
ROWNUM=1

UNION

SELECT * FROM (SELECT * FROM EMP ORDER BY EMP_NO DESC)
WHERE ROWNUM=1;

Is This Answer Correct ?    14 Yes 4 No

how to retrieve 1st and last row of table without using group functions??..

Answer / sudipta santra

For the 1st row:

select * from emp where rownum<2 order by empno;

For the last row:

select * from emp where rownum<2 order by empno desc;

Is This Answer Correct ?    14 Yes 5 No

how to retrieve 1st and last row of table without using group functions??..

Answer / nathan

SELECT *
FROM (SELECT emp.*, ROWNUM rn
FROM emp)
WHERE rn = 1 OR rn = (SELECT COUNT (*)
FROM emp);

Is This Answer Correct ?    3 Yes 0 No

how to retrieve 1st and last row of table without using group functions??..

Answer / rajesh

SELECT * FROM (SELECT * FROM EMP ORDER BY EMP_NO) WHERE
ROWNUM < 2

UNION

SELECT * FROM (SELECT * FROM EMP ORDER BY EMP_NO DESC)
WHERE ROWNUM < 2;

Is This Answer Correct ?    2 Yes 0 No

how to retrieve 1st and last row of table without using group functions??..

Answer / ajay reddy

Select * from (select e.*,rownum r from emp e) where r in(1,(select count(*) from emp));

Is This Answer Correct ?    0 Yes 0 No

how to retrieve 1st and last row of table without using group functions??..

Answer / ajitnayak

SELECT *
FROM EMP
WHERE ROWID = (SELECT MIN(ROWID) FROM EMP)
UNION
SELECT *
FROM EMP
WHERE ROWID = (SELECT MAX(ROWID) FROM EMP)

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Oracle General Interview Questions

how to create a new database in oracle?

6 Answers   TCS,


Explain the use of rows option in imp command.

0 Answers  


Hi friends can u send the oracle 9i full version download link?????????????? please reply ?

0 Answers  


Where is the export dump file located?

0 Answers  


Please explain me all types of Data models. Also give me the details if each model can have other name.for example:schematic data model is also known as conceptual data model and entity relation data model.

0 Answers  






Define Transaction ?

5 Answers  


what is the difference between functional dependecy and multilevel dependency?

0 Answers   Oracle,


HOW TO CONVERT ORACLE TABLE DATA (RECORDS)INTO EXCEL SHEEET?

3 Answers  


How to do paging with oracle?

0 Answers  


Using the relations and the rules set out in the notes under each relation, write table create statements for the relations EMPLOYEE, FIRE and DESPATCH. You should aim to provide each constraint with a formal name, for example table_column_pk.

0 Answers   Wipro,


What is cursor

4 Answers   TCS,


Explain the dml?

0 Answers  


Categories
  • Oracle General Interview Questions Oracle General (1789)
  • Oracle DBA (Database Administration) Interview Questions Oracle DBA (Database Administration) (261)
  • Oracle Call Interface (OCI) Interview Questions Oracle Call Interface (OCI) (10)
  • Oracle Architecture Interview Questions Oracle Architecture (90)
  • Oracle Security Interview Questions Oracle Security (38)
  • Oracle Forms Reports Interview Questions Oracle Forms Reports (510)
  • Oracle Data Integrator (ODI) Interview Questions Oracle Data Integrator (ODI) (120)
  • Oracle ETL Interview Questions Oracle ETL (15)
  • Oracle RAC Interview Questions Oracle RAC (93)
  • Oracle D2K Interview Questions Oracle D2K (72)
  • Oracle AllOther Interview Questions Oracle AllOther (241)