Write a query to get 2nd maximum salary in an employee table ?
Answers were Sorted based on User's Feedback
Answer / omkar hendre
select distinct(sal) from emp a where 2=(select count(distinct(sal)) from emp b where a.sal <=b.sal)
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / swapnil tikale
Select top 1 salary from (select distinct top 2 salary from employee order by salary desc) as sal order by salary ;
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / prem chhappesh
select max(salary) from emoplyee where salary not in(select max(salary) from employee)
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / tejasvita dhuri
select id,salary from (select id,salary,ROW_NUMBER()over (order by salary desc) as rowcol from emp)A
where A.rowcol=2
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / anita prasad
SELECT MIN(SAL) FROM (SELECT DISTINCT * FROM EMP ORDER BY DESC) WHERE ROWNUM<3;
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / satish
select rownum,employee_id,first_name,max(salary) from
employees
group by rownum,employee_id,first_name
having rownum<=2
order by rownum
| Is This Answer Correct ? | 5 Yes | 6 No |
Answer / deven
select top 1 salary from emp where salary <>(
select top 1 salary from emp order by salary desc) order by
salary desc
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / deepa
select min(salary) from (select salary from table_name order by salary desc) where rownum<3;
| Is This Answer Correct ? | 1 Yes | 2 No |
Answer / niladri saha
into my above solution,u can get whatever position u want,only by giving "n" at the place of "2" at row num. That the right way to write the query. That u can use in dynamically.
Thanks,
like if ur require ment to print empnames of having 3rd max salary,then put 3 at rownum.
Niladri Saha.
| Is This Answer Correct ? | 0 Yes | 1 No |
What are the operators used in select statements?
What is the difference between UNIQUE CONSTRAINT and PRIMARY KEY? 1. There is no difference. 2. A PRIMARY KEY cannot be declared on multiple columns. 3. A UNIQUE CONSTRAINT cannot be declared on multiple columns. 4. A table can have multiple PRIMARY KEYS but only one UNIQUE CONSTRAINT. 5. A table can have multiple UNIQUE CONSTRAINTs but only one PRIMARY KEY.
What does fetching a cursor do?
What is trigger with example?
How do I view tables in sql developer?
Mention what pl/sql package consists of?
how to drop an existing view in mysql? : Sql dba
What is full join in sql?
What programs use sql?
What is the importance of sqlcode and sqlerrm?
What are the two different parts of the pl/sql packages?
what are the maximum number of rows that can be constructed by inserting rows directly in value list? : 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)