how to get second highest salary in each department in sql

Solutions on MaxInterview for how to get second highest salary in each department in sql by the best coders in the world

showing results for - "how to get second highest salary in each department in sql"
Micaela
22 Jul 2018
1/* sql 2nd highest salary employee */
2select sal, ename
3from emp
4where sal =
5    (
6        select max(sal) from emp where sal <
7            (select max(sal) from emp)
8    )
9----------------------------------------------- option 2
10select *
11from 
12(
13    select ename, sal, dense_rank() over(order by sal desc) rank
14    from emp
15)
16where rank =2;
Abigail
08 Apr 2020
1SELECT E.Employers_name, E.dep_number, E.salary
2FROM Employers E
3WHERE 1 = (SELECT COUNT(DISTINCT salary) 
4        FROM Employers B 
5        WHERE B.salary > E.salary AND E.dep_number = B.dep_number)
6group by E.dep_number
Benjamín
11 Nov 2018
1--Find out the name of top earner in each departments
2--Output has Name, Department name and max salary of the department
3
4SELECT E.FIRST_NAME , D.DEPARTMENT_NAME, E.SALARY
5FROM EMPLOYEES E
6JOIN DEPARTMENTS D ON E.DEPARTMENT_ID = D.DEPARTMENT_ID
7WHERE SALARY IN(SELECT MAX(E.SALARY)
8FROM EMPLOYEES E
9JOIN DEPARTMENTS D ON E.DEPARTMENT_ID = D.DEPARTMENT_ID
10GROUP BY DEPARTMENT_NAME);
queries leading to this page
mysql get max salaryselect seceond higest query languagesql query get max salary each departmentsql query to get second highest salary using rownumhow to find the second highest salary in sqlsecond maximum in sqlgetting second highest salary in sqlselect second highest salary in sqldepartment wise second highest salary in sqlquery to find 2nd largest salary in sqlget max salary from each department sqlget 3rd highest salary in sqlwrite a query to find the second max salary7th highest salary in each department sqlsql get second highest valuesql find second highestwrite sql query to get the second highest salary among all employeeshow to find highest salary in sqlprint second highest salarysecond largest in sql queryprint second highest salary in sqlhow to 2nd highest salary in sqlfind second largest salary sqlfind top 2 salary sqlfind second max salary in sqlget second highest record in sqlemployee second highest salary in sqlhow to set second largest salary in sqlsql query to get third highest salaryhow to give find second highest salary in sql as second highest salaryhow to get third highest salary in sqlget second highest salary of a particular department sqlhow to get second highest salary in sql for all employeecalculate second highest salary in sqlprint name of second highest salary in sqlwrite a sql query to find 2nd maximum salaryselect max salary from each department in sqlhow to find the second highest number in sqlhow to get the second highest salary in sqlselect top 2nd highest salary for sql2nd max salary in mysqlsecond largest salary sqlsql query to find second maximum salary2nd highest salary query in sql2 highest salary in sqlselect second highest salary sqlsql query for find second highest salaryfind the second largest salary in sql querysql query to find max salary of an employeesecond highest salary in department sqlfind second highest salary using limit in sqlhow to find 2nd largest salary in sqlhow to display second highest salary in sql2nd highest salary in sql using limitget the last thee max salaried person from table via sql how to find second highest salary in sql without using subquerysql find second highest salarysql command for 2nd highest salaryhighest salary in sqlfind max salary in each departmenthow to find employee who have the second highest salary in sqlemployee with second highest salary sqlsecond highest salary from salary colun sql commandgetting maximum salary from each department the tables in each deoartment is differentmaximum salary in each department sqlget second highest salary today in sqlsalary in my sqlhighest salary in sqfind the second highest salary among the given table 28sql 29query to find second highest salary from each department of a companyget second highest salary in sqlsql query to find the 2nd highest salarysecond largest salary sql from employee tablehow to find second max salary in sqlhow to get 2nd highest salary in sqlsql get third highest salary2nd max element sql queryquery to find highest salary in each departmentsecond highest salary also get other columns in sqlsecond height salary sqlsql query to find the second highest salaryhow to second highest salary in sqlwrite an sql query to find out the second highest salary from an employees table sql select employee which have the max salary in a given departmentget highest salary in sqlwhat is the query for second highest salary in sqlsecond most highest salary in sqlhow to find the second biggest salary sqlgroup by in sql write the query for finding the second highest salarywrite a sql query to find max salary and department name from each department how to print 2nd highest salary in sqlhow to find the third highest salary in sqlhow to find second highest salary in sql using limitsql query for getting third highest salary from given salary columnsecond highest salary employee sqlfind highest salary in each department sqlselect name from emp where salary 3e 28select max 28salary 29 from emp where salary 3c 28select max 28salary 29 from emp 29 29 3b2nd largest value in mysqlhow to find second largest salary in sqlsql query find second highest salaryfind the person with 2nd highest salary sqlwrite a query to get the second highest salary from employeeorder by second highest salary in sqlselect max 28salary 29 as salary from employee where salary 3c 28select max 28salary 29 from employee 29 3b what is the output of this query 3fto find 2nd highest salary in sqlfind second largest salary in sqlselect highest salary in sql serversql to find second highest salaryhow to find the second max salary in sqlfind 2nd highest salary in sqlhow to find highest salary in sqlsql get the second highest valuehow to add employee name and department name in this query select 28select max 28salary 29 from employee 29 max salary 2c 28select max 28salary 29 from employee where salary not in 28select max 28salary 29 from employee 29 29 as 2nd max salary 3bhow to get third maximum salary in sqlquery to find second highest salary of employeeselect employee with max salary in each department sqlhow to get second highest salary in each department in sqltop salary from each department in sqlsecond max salary in sql querysecond highest salary in sqlfind second highest salary in sqlmax salary in each department in sqlsql find third highest salarysecond max salary in sqlto get second max employee salary sql querysql query to display 2nd highest salaried employee details and may ask for nth highestsecond highest salary in sql using limitfind max salary from each department in sqlhow to get the 2nd highest salary in sqlfind max salary in sql2nd largest salary in sqlfind the 2nd largest salary in sqlsql problem to find nth highest salarysql select second highest salaryget second highest salaryhow to find 2nd highest salary in sqlget second highest salary sqlhow to pull 2nd maximum record sqlhow to print highest salary in sqlsecond highest salary sql serverhow to find 2nd lowest salary in sqlsql query to get second highest salary using sub queryfind second maximum salary in sqlsql query to get 2nd highest salarysecond highest salary sqlhow to find 2nd highest number in sqlin this mysql challenge 2c your query should return the informatioi for the employee with the third highest salary write a query that will find this employee and return that row 2c but then replace the di visionidwrite a query to display the second highest salary in a particular departmentsecond highest salaryselect second max salary in sqlquery second highest salary sqlselect 2nd highest salary from employee table in sqlsecond lowest salary in sqlsql query to find out the second highest salary find second highest salary in sql using limitsql query to find max salary from each departmenthow to query second lowest salary from employee table in sqlselect second highest salary from employee table get max sum of salary from each department sqlwrite a sql query to find the second highest salary from employees table find out max salary between dept 3d 20 and 40query to get max salary of employee from each departmenthow to give find second highest salary in sqlhow to find maximum salary without using max function in sqlhighest second salary in sql using limitsql find second highest salary employeeget the second highest salary in sql sql server 2nd highest salaryfinding second highest salary in sqlfinding top2 nd highest salary in sqlfind the second highest salary in sqlselect second highest salary from each department sqlget top salary from each department in sqlwho is the max salary getter for each department in sqlselect nth highest salary in sqlhow to find second highest salary in sqlselect employee with second highest salary sqlsql 2nd highest salaryfind the third highest salary in sqlquery to select the emp of max salarydefine the second cte 2c itsalary 2c with the fields id and salary csdnto second last highest salary in sqlsql query to select second highest salaryemployee with max salary sqlwhat is the query to find second highest salary of employeequery to get second max salarymax salary from each department sqlhow to get second highest salary using sql how to find the department highest salary in sql 3fto get second highest salary in sqlhow to get maximum salary of an employee in sqlwrite the sql command to fetch 2nd highest salary from the employee table max salary by department sqlselect max 28salary 29 from employee where salary not in 28 select max 28salary 29 from employee 29 3bsql max salary by departmentsql second highest salarywithot aggregateget 2nd hieghest salary of employee using sql queryms sql server salary doublesql get time by second highest salarywrite a sql query to get the second highest salary from the employee tablehighest salary in each department sqlsql second highest salarysql 2bhighest salarywrite a sql query to get the second highest salary from the employee table how to find third highest salary in sqlsecond highest salary database querywhere salary 3d max 28salary 29 sqlwrite a query to retrive 2nd highest salary from a tableget 2nd highest salary in sqlsql query for second highest salaryfind second max salary in sql using limitsql query to select 2nd highest salarywrite a sql query to get the second highest salary from employee tablesql query to find 2nd highest salaryfind third highest salary in sql serversql highest salary in each departmentfind maximum salary in sqlsql query to find the employee with the second highest salarysql second highest salary of employeeselect 2nd highest salary in sqlselect top 2 salary from employee tablehow would you find the second highest salary from the below table mysql 3ffind second max salary query sqlsql second highest salary querysql query to find second highest salarysql query for getting second highest salarymaximum salary from each department sqlget second highest salary from query sqlsql max salarysql max salary of employeefind third highest salary in sqlsql query to find highest salary of employees in each departmentget max salary from each department in sqlwrite an sql query to show the second highest salary from a tablewrite sql query to find second highest salary of employeehow to get max from each department in sqlselect max salary using top sqlq how to get the second highest salary using sql 3fhow to get max salary in each department in sqlsecond highest salary in a department in sqlquery for second highest salarysql sql query to get maximum salary in each departmentsql server second highest salaryquery to get second highest salarysecond highest in sqlmax salary from each department in sqlhighest second salary in sqlget second highest salary in sql using ctesql query to return second highest salarysql query to find third highest salary of employeeselect highest salary from each department in sqlwrite an sql query to show the second highest salary from a table write a sql query for second highest salaryfind max salary from each department2nd maximum salary in sql emp tanlesql sql query to get maximum salary in each department from single table2nd highest salary in sql 5csql query to get second highest salaryhow to find highest salary in each department in sqlhow to find second highest salary in sql using subqueryfirst highest salary in sqlfind the employee with the second highest salary using sqlsql query to find second highest salary of employeewrite sql query for getting third highest salary from given salary columnsql query to find first three highest salary for each yearwith the highest salaries sqlget third highest salary from each department sql serversql query to find employee who has second highest salarymax salary employee all info in sqlfind 2nd maximum salary per departmentcoderbyte mysql challenge mysql challenge 2c your query should return the informatioi for the employee with the third highest salary how to get second highest salary in sqlget max salary in sql2nd highest salary in each department sqlsql query for 2nd lowest salaryhow to find out 2nd highest salary in sqlget last max salary from each department sqlfind max salary and youngest employee in every department sql2nd highest salary in sqlsql query to find 2nd lowest salarysql query to find third highest salarysql query for getting fourth highest salaryhow to get second maximum salary in sqlfind the 2nd highest salary in sqlprint second and third highest salary in sqlhighest salary from each department in sqlsql query to show the second highest salary from a tableselect 2nd max salary in sqlsecons hiest salary in sqlget 2nd highest salary from employee table2nd highest salary in sql by departmentget third highest salary in sqlfind second highest salary in sql without subquerywrite sql query to find max salary from each department 28print name and the max salary 29sql second highest using fetchhow to find highest average in sqlquery to find second highest salary from the given tablehow to get highest salary in sqlhow to get maximum salary in sqlsql query to query nth largest salaryhow to find second highest salary in sql without using corelated querysql query to find details of highest salarysql command to find second highest salaryhow to get second highest salary in each department in sql