how to retrive only second row from table?
Answers were Sorted based on User's Feedback
Answer / naresh raju
select * from emp where rownum<=2
minus
select * from emp where rownum<2
| Is This Answer Correct ? | 63 Yes | 12 No |
Answer / hema
Both the above answers give no correct result..
The first says bind variable should be declared for :n,
and second gives no rows selected...
| Is This Answer Correct ? | 34 Yes | 11 No |
Answer / umadevi
SELECT * FROM emp a WHERE 2 = (SELECT COUNT(rowid) FROM
emp b WHERE a.rowid >= b.rowid)
now it will work. instead of :n we have mention row number.
| Is This Answer Correct ? | 26 Yes | 10 No |
Answer / monika
SELECT * FROM(SELECT a.*,row_number() over(ORDER BY NULL)
rn FROM emp a)
WHERE rn=2
| Is This Answer Correct ? | 18 Yes | 6 No |
hi this tulasi .....+91-9951123501
in SQL Server 2000 we write as...
declare CurTemp scroll cursor for
select top 2 * from <table_name>
open CurTemp
fetch last from CurTemp
close CurTemp
deallocate CurTemp;
in ORACLE , we can write as..
select * fom <table_name>
where rowid=(select rowid from <table_name>where rownum<=2
minus
select rowid from <table_name>
where rownum<2;
so try it ...
| Is This Answer Correct ? | 17 Yes | 5 No |
Answer / zeljko
This answer_10 will work only if there is not order by used
on select statement.
I recommend using dense_rank function to get second row out
as in example;
SELECT * FROM (
SELECT id, first_name, salary,
DENSE_RANK() OVER(ORDER BY salary desc) row_order
FROM employee)
WHERE row_order = 2;
| Is This Answer Correct ? | 11 Yes | 2 No |
Answer / sandhya rani
This is perfect answer...
and do not misguide the ppl by simply writing wrong answer.
until and unless u r perfect..pls do not share your answer
select * from emp where rownum<=2
minus
select * from emp where rownum<2
| Is This Answer Correct ? | 12 Yes | 3 No |
Answer / vamsi krishna
this query will give the correct answer.
all the answers which are given above are absolutely wrong.
(take it easy who posted them)
select * from (select rownum as r1,empno,ename,sal,deptno
from emp) where r1=2;
(take default emp table for execution)
| Is This Answer Correct ? | 12 Yes | 8 No |
Answer / bindu
select * from (select rownum r1,e.* from emp e)
where r1=2;
| Is This Answer Correct ? | 8 Yes | 4 No |
Answer / rajasekar.p
select * from (select a.*,rownum aa from orders a )
where aa=2
Please verify the same you will get the correct answer
Regards
P.Rajasekar
| Is This Answer Correct ? | 5 Yes | 3 No |
What makes a good primary key?
mail-id table contains two columns(email_id,userid) it contains different types of mail-ids,and no of users. here username length is differ na,(ex- tamil@yahoo.com,joshua@hotmail.com like) now i want to fetch the email-ids only starting from '@' (ex-@gmail.com,@yahoo.com,@hotmail.com
What does desc stand for?
What is the difference between clustered and non-clustered index in sql?
What is memory optimized?
How many levels can subqueries be nested in a FROM clause?
Write a query to find the employees from EMP table those who have joined in Monday. (there is a column as hiredate which is a date column i.e values are like 03-DEC-81)
What are the two types of periodical indexes?
what is 'mysqlcheck'? : Sql dba
What is the difference between rollback and rollback to statements?
If you have to declare procedure1,procedure2 in package specification and if you have to declare procedure1,procedure2 and procedure3 in package body? is it compilation or not and execute or not? what type of error is given please
What is basic structure of pl 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)