Write a query to get 2nd maximum salary in an employee table ?
Answer Posted / basheer
ex:
Raj 200
kamal 300
hajka 500
Suresh 200
so 1st max salary is 500,2nd is 300,3rd is 200
we need 2nd maximum only(i.e 300)
Query is below
SELECT MIN(SALARY) FROM EMPLOYEE WHERE SALARY IN (SELECT
DISTINCT TOP 2 SALARY FROM EMPLOYEE ORDER BY SALARY DESC)
I've checked this query.
it will give 2nd maximum value.
if it is 3rd max salary then use TOP 3 instead of TOP 2
if u need detail explanation:
1)
Qry: SELECT DISTINCT TOP 2 SALARY FROM EMPLOYEE ORDER BY
SALARY DESC
Output:500
300
2)
SELECT MIN(SALARY) FROM EMPLOYEE WHERE SALARY IN (SELECT
DISTINCT TOP 2 SALARY FROM EMPLOYEE ORDER BY SALARY DESC)
ans: it gets minimum salary from subquery( from above 1st ans)
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
when MSQL8.0 is in market
What is the maximum number of triggers, you can apply on a single table?
What pl/sql package consists of?
what is table? : Sql dba
How is pl sql different from sql?
write an sql query to find names of employee start with 'a'? : Sql dba
Why truncate is faster than delete?
What are different joins used in sql?
what are dynamic queries in t-sql? : Transact sql
What are different types of sql?
How do I create a sql database?
What does seeding a database mean?
Is there a 64 bit version of ssms?
What is bitemporal narrowing?
What is forward declaration in pl sql?