how to find the second highest salary from emp table?
Answers were Sorted based on User's Feedback
Answer / radha sri seshu.kolla
select max(sal) from emp where level=2 connect by prior
sal>sal group by level;
| Is This Answer Correct ? | 17 Yes | 22 No |
Answer / shalina bajaj
select sal from emp a
where $number = (select count(distinct(sal))
from emp b
where a.sal <= b.sal);
| Is This Answer Correct ? | 11 Yes | 17 No |
Answer / prasanthi
select * from (select rownum r,a.* from (select distinct
sal from emp order by sal desc)a)where r=&i
sql>enter i value(enter manually) 2
| Is This Answer Correct ? | 54 Yes | 62 No |
Answer / prasanna
select A.* from employee A where 1=(select count(distinct
B.sal) from employee B where B.sal>A.sal)
| Is This Answer Correct ? | 63 Yes | 71 No |
Answer / ved
select sal from emp
where limit,1
order by sal desc
| Is This Answer Correct ? | 12 Yes | 20 No |
Answer / raghavendraprasad
select salary from emp e where &n-1=(select count(*) from
emp where salary>e.salary);
| Is This Answer Correct ? | 7 Yes | 15 No |
Answer / ramesh lavanuru
SELECT sal1 "salary"
FROM (SELECT ROWNUM rownum1 ,sal1
FROM (SELECT sal sal1
FROM emp
ORDER BY sal DESC
)
)
WHERE rownum1=:p_highest;
Note:- 'p_highest' here we can give the number as we want
to display the highest salary.
| Is This Answer Correct ? | 52 Yes | 63 No |
Answer / avinav
By using the rank function we can get the 2nd highest
salary from the emp table
| Is This Answer Correct ? | 10 Yes | 25 No |
Answer / pradeep
select sal from emp
where rownum=2
order by sal desc
| Is This Answer Correct ? | 10 Yes | 50 No |
Answer / rameshwari
select ename,esal from
(select ename,esal from hsal
order by esal desc)
where rownum <=2;
| Is This Answer Correct ? | 123 Yes | 242 No |
what happens if null values are involved in expressions? : Sql dba
Does oracle use sql?
What are two statement types in sql?
What is procedure function?
How does cross join work?
how to see the create table statement of an existing table? : Sql dba
I want to display the employees who have joined in last two months. (It should be executed randomly means If I execute the query in March it should display Jan and Feb joined employees. Same query if i execute in Feb, 2007 it should display dec, 2006 and jan 2007 joined employees.
Does indexing improve query performance?
Explain the difference between sql and mysql.
Name some usages of database trigger?
Can you select everything, but 1 or 2 fields, without writer's cramp?
what does the t-sql command ident_current does? : Transact 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)