second highest salary in sql

Solutions on MaxInterview for second highest salary in sql by the best coders in the world

showing results for - "second highest salary in sql"
Paul
12 Mar 2016
1Both options you find max as a subset and then exclude from main select
2sql> SELECT MAX( col ) FROM table
3 	WHERE col < ( SELECT MAX( col ) FROM table);
4sql> SELECT MAX(col) FROM table 
5WHERE col NOT IN (SELECT MAX(col) FROM table);
Pedro
28 Feb 2020
1SELECT TOP 1 salary
2FROM (
3SELECT DISTINCT TOP N salary
4FROM #Employee
5ORDER BY salary DESC
6) AS temp
7ORDER BY salary
James
29 Sep 2016
1Here is the solution for nth highest
2salary from employees table 
3
4SELECT FIRST_NAME , SALARY FROM 
5(SELECT FIRST_NAME, SALARY, DENSE_RANK() OVER
6(ORDER BY SALARY DESC) AS SALARY_RANK
7FROM EMPLOYEES)
8WHERE SALARY_RANK = n; 
Davide
02 Feb 2018
1SELECT MAX(SALARY) 'SECOND_MAX' FROM EMPLOYEES
2WHERE SALARY <> (SELECT MAX(SALARY) FROM EMPLOYEES);
Elias
12 Jan 2019
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;
Eric
23 Feb 2020
1SELECT MAX(SALARY) 'SECOND_MAX' FROM EMPLOYEES
2WHERE SALARY <> (SELECT MAX(SALARY) FROM EMPLOYEES);
3
4
5OR
6
7Here is the solution for nth highest
8salary from employees table 
9
10SELECT FIRST_NAME , SALARY FROM 
11(SELECT FIRST_NAME, SALARY, DENSE_RANK() OVER
12(ORDER BY SALARY DESC) AS SALARY_RANK
13FROM EMPLOYEES)
14WHERE SALARY_RANK = n; 
queries leading to this page
5th highest salary in sql serversql query to display second highest salary for every employeewrite a query to determine the nth 28say n 3d5 29 highest purch amt from orders table second highest salary sql queryhighest salary query in sqlmysql get max salarysql query to find nth highest salary of employeefind nth highest salary in sql servernth highest salary mysqlsecond largesst salary mysqlhow to get second highest salary in sql serverget 2nd highest salary in sqlhow to find highest salary in sqlhow to give find second highest salary in sqlhow to find 2nd highest number in sqlhow to find the third highest salary in sqlsecond largest salary sql by maxsecond highest from sqlwrite an sql query to show the second highest salary from a table ms sql find nth highest salary3rd height salary mysqlsql query to get second highest salary using rownumselecting second highest salary in sqlselect highest salary from table in sqlsql query to find second highest salary of employeeget second max salary queryn highest salary in sqlget the second max value sql find highest salary in each department sqlselect 2nd max salary in sqlget second max from sql tablegroup by in sql write the query for finding the second highest salarywrite an sql query to find the nth highest salary from table sql third highest valuesecond highest salary employee sqlsql get lowest valueselect 3 max salary in sql2nd max salary query in sqlthird hightest sql logicfind out third highest salary in sqlsecons hiest salary in sql without limitget second highest salaryfind the second highest salary in sqlhow to get a second highest salary in sqlthird maximum salary in sqlnth highest salary in sql without limitsql query to find the nth highest salaryquery for second highest salaryhow to find max paid salary in sqlfind the thirt hiegest salry in sqln m sqlmax 3rd salary sqlmost efficient query to second largest valueget the last thee max salaried person from table via sql list the highest salary in sqlfind second max salary in sql using limithow to get 4th highest salary in sqlnth highest salary in sql by limithow to find last 2nd highest salary in sqlselect max salary in sql2nd highest number in sqlget second highest salary in sqlget n highest salary sqlhow to find 2nd highest salary in sqlhow to find maximum salary without using max function in sql2nd maximum salary in sql emp tanlesecond highest salary also get other columns in sqlsecond height salary mysqlwrite a query to return top 5th record of an employee based on salary given all required columns are present in same tablehow to get 3rd maximum salary in sqlfind nth highest salary in sql with ctesecond highest salary sql using limittop 3rd salary in mysqlfind 2nd highest salary in sql using rownumsql query to query nth largest salaryfind the second largest value in column of a table2nd max element sql queryfind out the highest salary in sqlfind the person with 2nd highest salary sqlhow to second highest salary in sqlfind second highest number in array in sqlget second highest salary in mysqlsecond max salary from employee table3rd highest salary in sqlhow to find the second maximum salary in sql3rd highest salary in sql sql select second maxget 2nd highest salary from employee tablegroup by in sql 2c write the query for finding the second highest salarysql query to find third highest salaryquery for second highest salary in sqlfinding top2 nd highest salary in sqlhow to select 3rd highest salary in sqlthird highest or second highest salary queryfind second maximum salary in sqlwrite a sql query to get the second highest salary from employee tablesecond maximum sql queryfind second second highest salary in sqlwrite a sql query to get the second highest salary from the employee tableget nth largest salary sqlhow to find top 2 highest salary in sqlhow to get the highest salary from the employee table in sqlfind the second highest salary among the given table 28sql 29 3a find 5th largest salary in a given salary table how to get 2nd max value in sql10th highest salary in sqlsql query to select 2nd highest salarysql command to find nth highest salary2nd highest salary query in sqlsql queries for highest salary2nd highest salary in sql 5cselect second highest salary in sql with other datasql get second highestfourth highest salary in sqlsql get third highest salarysecond highest salary in sql serverget the second highest salary in sql serversql server nth highest salary2nd max salary in sqlsql server 2nd highest salary2nd min salary in sql3 highest salary in sqlsecond highest no in table in sqlfind the nth highest salary in sqlselect top 2nd highest salary for sqlselect top 2 salary in sqlhighest second salary in sql using limitquery to select the emp of max salaryquery for taking second max salary in sqlfind nth max salary in sql4th highest salary in sql using limitwrite a sql query to print highest salary in consecutive yearsto find 2nd highest salary in sql4 highest salary in sqlquery to get second highest salarymysql second highest salaryquery to find 5th highest salary in sqlselect 3rd highest salary in sqlcalculate 3rd highest salary sqlsql query to find the 2nd highest salaryto get second max employee salary sql querynth highest salary in each department sql serversql query to find second highest salarykth largest salary in sql order byhow to get the nth highest salary in sqlsql query find second highest salarysql 2nd highest salaryfind nth highest salary in sqlhow to find second max salary in sqlselect second highest sqlwrite a query to retrive 2nd highest salary from a tablehow to 2nd highest salary in sqlsql qury to get the second highest salarysecond minimum salary in sqlhow to get 2nd lowest salary in sqlprint second highest salary2nd maximum salary in sqlq how to get the second highest salary using sql 3ffind maximum salary in sqlsql nth highest salary where salary is givencoderbyte mysql challenge mysql challenge 2c your query should return the informatioi for the employee with the third highest salary print second highest salary in sqlsql second highest salarysql query to find out nth highest salaryget the 2nd highest salary in sqlfind highest salary in sqlfind second max in sqlfind top 2 salary sqlget second highest record in sqlsecond largest in sql queryselect second max salary in sqlfind the highest salary in sqlhow to select 2nd highest salary in sqlhow to get 3rd max salary in sql3 max salary in sqlsql query to second highest salaryselect nth highest salary in sqlsql query second highest salaryget second most highest salary sqlget second highest salary today in sqlsql query to find nth highest salary using limitget the second highest salary in sqltop second highest salary in sql3rd max salary in sqlcalculate second highest salary in sqlfind second max salary in sqlhow to calculate second max salary in sqlhow to find second highest salary in sql without using corelated queryhow to get the second highest salary in sql 3ffind second max value in sqlnon correlated subquery to find second hoghest salary with exampleswhat is the query for second highest salary in sqlorder by second highest salary in sqlselect 5th highest salary in sql servermysql query to get second highest salarysecond highest salary in mysql emp table querysql how to get 2nd highest salarysql query to find 2nd lowest salarynth highest salary in sql limitselect the highest salary in sql query second highest salary of an employee sqlsql query nth highest salarysql query to find 3rd highest salaryhow to get second highest salary in each department in sqlt sql second highest salaryfind second largest salary in sqlsecond highest salary in sql query3rd maximum salary in sqlcount second highest marks in sql quertnth max salary in sqlsql command to find second highest salarywrite a sql query to find the second highest salary from employees table how to find max salary in sql using subquerysecond nd max salary in sqlwrite a query to get third highest value oraclewrite a sql query to get the nth highest salary from the employee table sql query to get second highest salary using sub queryget the 3rd highest salary sqlmysql 3e select min 28salary 29 from user where salary in select salary from user order by salary desc 3b2nd largest element 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 3fsql query kth highest salary select highest salary in sqlsql query to find people with 2 highest salrieshow to find 2nd max salary in sqlquery to get 2nd highest salary2nd and 3rd highest salary in sqlsql query for nth highest salarysql server second highest salaryselect max 28salary 29 from employee where salary not in 28 select max 28salary 29 from employee 29 3bselect seceond higest query languagehow to query second lowest salary from employee table in sqlfinding second highest salaryselect second highest salary in sql without using limitreturn 2nd hightst value in sqlsql queries to find nth highest salarysql query to find n highest salaryfind third max salary in sqlhow to find second highest salary in sql 3fsecond max salary in sqlhow to find the 3rd highest salary in sqlsecond lowest salary in sqlfind 4th highest salary in sqlhow to find nth highest salary in sql 3fsql 4th highest salerywrite the query to get the 2nd highest salary in sql write an sql query to determine the 5th highest salary without using top or limit method select nth max salary in sqlsql query highest salarysecond highest salary querysql to find second highest salaryn highest salary in sql in big query get highest salary in sqlsql nth highest salarysql query to find third highest salary of employeeto find nth highest salary in sqlsql get second highest valuehow to nth highest salary in sqlfind nth largest salary in sqlmax 4th salary from employe tablehow to find the 2nd highest salary in sqlsecond largest sql queryselect name from emp where salary 3e 28select max 28salary 29 from emp where salary 3c 28select max 28salary 29 from emp 29 29 3bquery to find nth highest salary in sqlwrite a sql query to get the second highest salary from the employee table sql query for second largest salarygetting second highest salary in sqlhow to select 2nd highest salary in mysqlhow to fetch third highest salary in sqlsql for nth highest salarysql find second highest salary2nd highest salary from table sql query for finding nth highest salarysql query to find 2nd highest salaryfind the second largest salary in sql queryselect the 5 th highest salary in sqlquery to select employee with max salarythird highest salary sqlto second last highest salary in sqlhow to get second highest salary using limit in sqlgetting nth highest salary sqlfind the 2nd largest salary in sqlquery to find second highest salary of employeesql query to find the second highest salary of employee 3fsecond highest salary sqln highest salary in mysqlselect 2nd highest salary in sqlselect highest salary in sql servernth salary in sqlfind second largest salarysql select second highest valuewhere salary 3d max 28salary 29 sqlsql query to find the employee with the second highest salaryselect second highest value sqlnon correlated subquery formula to find second hoghest salary with exampleshighest lowest salary sqlsecond highest salary query in sqlsql select 2nd max salaryget max salary in sqlhow to get second highest salary in sql for all employeehow many tuples will be retrieved by using following query on given table 3fselect max 28emp sal 29 from employee group by dept no 3b 2ain sql find nth highest salarynth highest salary sql query2nd largest salary in sqlsql query to find out the second highest salary 2nd highest salary from employee tableselect top 2 salary from employee tablesecond highest salary sql servergetting 4th highest salary in sqlsql query to select second highest salaryget third highest salary in sql2 max salary in sqlselect query for second highest salarysql query to find the second highest salaryhow to 3rd maximum salary in sql queryprint second and third highest salary in sqlmin max salary in sqlsql second highest salary of employeehow to find the second biggest salary sqlsecond largest salary sqlhow would you find the second highest salary from the below table mysql 3fsql select second largest valuesecond max salary in sql serversecond maximum in sqlsql second highest salarywithot aggregateselect max salary record sqlfind the employee with the second highest salary using sqlselect max salary sqlsql query for max salarysecond highest value in sqlstore the table after joining in sql and then take the second largest element sql 3rd highest salarysql second maxlowest salary in sqlselecting second max value sqlget nth max salary sqlhow to find 2nd largest salary in sqlsql 2bhighest salarysql query to return second highest salarysecond max sql9th max salary from sqlhow to find max salary in sqlhighest second salary in sqlto get second highest salary in sqlhow do you 2nd highest salary in sqlsecond highest salary in sql using rownumwith the highest salaries sqlsecond max salary using group by havingfind the 2nd highest salary of an emplyeefind second highest salary sqlhow to select highest salary in sql4th maximum salary using subquery in mysqlhow to get nth max salary in sqlselect second max value in sqlprint name of second highest salary in sqlwrite a sql query for second highest salarymultiple second highest sqlfind second largest salary sqlselect nth highest salary in sql server2nd hioghest salary using rank functionsecond highest sqldisplay the second highest salary employeenth highest salary in sql querysql query 5th highest salarysql select nth highest salaryselect max 3 salary in sqlsql find second highest salary employeehow to find 3rd highest salary oehr in sqlnth highest salary in sqlfind 2nd highest salary in sqlfind 3rd max salary in sql using limitselect the 2nd maximum sqldisplay the nth highest salary drawing employee details mysqlhow to select top 3 salary in last 30 daysw3 school 2nd largest salary queryselect second highest salary sql problem onlinefind second max sqlsecond highest salary from salary colun sql commandmysql get second highesthow to print 2nd highest salary in sqlthird highest salary in sql using rownumwrite an sql query to find the nth highest salary from tablewrite an sql query to determine nth the highest salarysecond height salary sqlfind the third highest salary in sqlsql query to find the person with the third highest salarysecond minimum salary sql queriessql query for find second highest salaryhow to find employee who have the second highest salary in sqleasiest way to find nth highest salaryget second max record in sql serverfind 2nd max salary in sqlmysql nth highest salaryin 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 visionidselect 5th highest salary in mysqlfind 2nd last max in sqlemployee second highest salary in sqlms sql server salary double2nd max salary in mysqllist the employees with the heighest salaryfind the 2nd max salary in sqlnth highest salary in mssqlsecond highest record in sqlnth highest salary in ms sql serverget top 3 highest salary in sql without window function2nd highest salary in each department sqlsql queries to print second highest salarygive me a query to find out the second largest compensation in an organization 3fwrite a query to find the second max salarysecond highest salary in sql using limitdetermine the 5th highest salary without using top or limit method third highest salary in sql3rd max salary sql queryquery to select the 5th largest salary from the employee tablesecond highest salary my sqlsecond highest salary in sqlsecond max in sqlselect max salary for all the employeefinding second highest salary in sqlquery to get second max salaryselect second highest salary in sql without using maxmax salary in sqlsql select the second highest countsql aggregate functions to get second maxsql query for 2nd highest salarysql query to find out highest salary from thehow to get nth highest salary in sqlsecond highest salary in teradatafinding the third highest salary in sql2nd highest salary in sqlhow to find second highest salary in sqlhow to find 5th highest from sqlhow to give find second highest salary in sql as second highest salarysecend highest salary sql query5th maximum salary sqlsql query to get second highest salaryfind second highest salary in sql using limitsecond max salary in sql queryget second max value in sqlhow to get 3rd highest salary in sqlsecound highest value in sqlhow to get second max in sqlmin salary in sqlhow select second field of select in sql with maxget second highest salary of a particular department sqlsecond highest salary insqlsecond highest salary in mysqlsecond largest salary in sqlhow to find highest average in sqlselect second highest value sqlsql query on finding the second highest salary from the employee table how to set second largest salary in sqlfind 3rd maximum salary in sqlsql get second maxfetch second highest salary sqlmax salary in nth sqlsql get 3rd highest salaryhow to select the second highest value in sqlhow to select third highest value in sqlhow 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 3bsql query to find 2nd maximum salaryfind the 2nd highest salary in sqlselect second max id from table sqlsecond maximum salary in sqlfirst highest salary in sqlfind third highest salary in sql serversql find second highesthow to get salary from another table in sqlwrite a query to figure out the highest employee salary the column is 27salary 27 third max salary in sqlhow to find nth highest salary in sqlhow to find top 2 salary in sqlhow to get max salary in each department in sqlsecond nth highest salary in sqlhow to find minimum salary in sqlhow to display second highest salary in sql2nd highest salary sql queryget second highest salary in sql using ctewrite a query for getting second largest salary from table 22employee 22 captionless imagefind nth higest salary in sqlsecons hiest salary in sqlfirst max salary in sqlget second highest salary from query sqllist the employee with the second height salaryhow to only get the highest salary in sql2nd largest value in mysql2nd highest salary sqlquery second highest salary sqlsql query to show the second highest salary from a tablesql query to find highest salarysql second highestselect max salary from employee tableaccess sql select max datesecond largest mysqlsql query to find details of highest salarysql find second maxhow to find the second highest salary in sqlcalculate 2nd highest salary sqlget nth highest salary in sqlhow to find the second largest number in sqlfind second highest salary in sql without subquerynth highest salary sqlfind third highest salary in sqlgiven a table of employees and their salaries 2c write a query to find employee with the second highet salaryhow to find second highest salary in sql using subqueryhow to get 2nd max salary in sqlsql query for getting second highest salarysql second highest using fetchselect second highest salary in sql querysecond largest number sql querywrite a sql query to print highest salary in 3 consecutive years4th maximum salary using subqueryhow to pull 2nd maximum record sqlselect second highest salary sqlhow to find second highest salary in sql using limitsecond max salary using havinghow to find second max value in sqlhow to find out 2nd highest salary in sqlget 3rd highest salary in sqlsql select second highestmysql 2nd highest salarysql query to display second highest salarysql query to find employee who has second highest salaryfind second highest row sql2 highest salary in mysqlhow to get third highest salary in sqlhow to select 2nd highest value in sqlfind the third max salary in sqlselect second highest in sqlhow to find the 2nd highest salary in sql servern highest salary in mysql using correlated subquerysecond most highest salary in sqlwrite a sql query to get the third highest salary of an employee from employee table 3f2nd highest salary in sql using limit3rd highest salary in sql using limit4 th max salary sql commandmax 3 salary in sqlhow to find highest salary in sqlselect distinct 28salary 29 from table order by salary desc limit n 2c1define the second cte 2c itsalary 2c with the fields id and salary csdnsecond maximum record from sqlhow to select second highest value in sqlselect max salary using top sqlsql find third highest salarynth highest salary in sql with explanationhow to calculate the second highest salary in sqlfind the second max in sqlsql highest salaryfind nth highest record in sqlnth minimum salary in sqlfind nth highest salary in sql using limitsql query to display 2nd highest salaried employee details and may ask for nth highesthow to find top 3 salary in mysqlsql query for 2nd max salarysql query for second highest salaryselect third max salary in sqlget second highest value sqlgive second highest salary in sqlselect second highest salary from each department sqlsalary in my sqlto find second highest salary in sqlsql find the nth highest salarytop 2 salary in sqlfind nth max salary in sql server3rd highest salary sql queryhighest salary sql querygetting 3rd highest salary sqlsql problem to find nth highest salaryhow to find second highest salary in sql without using subqueryfind second highest salary in sqlhow to get 2nd highest salary in sqlfifth highest salary in sqlsql query to retrieve fifth highest salarysql second highest salary queryget 2nd hieghest salary of employee using sql querynth largest number sql query3rd height salary sqlhow to find out 3rd highest salary in sqlsecond largest in sqlgetting nth highest salary sql using limitwhat is the query to find second highest salary of employeen max salary in sqlhow to select nth highest salary in sqlhow to get second highest salary using sql how to get highest salary in sqlhow to find the tenth highest salary in sqltop 2nd highest salary in sqlsql query to find second maximum salaryhighest 2nd salary in sqlsecond highest salary database querywrite the sql command to fetch 2nd highest salary from the employee table sql command for 2nd highest salaryselect employee with second highest salary sqlsecond highest query in mysqlsql get time by second highest salaryfind the n highest salary in sqlsql query to find the second highest salary of an employeethird highest salary in sql using limitwrite the query for finding the second highest salaryselect top 2nd classmax function in sql to find second highestselect second highest salary from employee table how to find the second highest number in sqlhow to find third highest salary in sqlhow to get the second highest salary in sqlhow 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 3b in mysqlhow to get 2 highest salary using sqldquery display 5 th highest salaryfind 2nd rank in sqlhow to find 3rd highest salary in sqlsql select 2nd highest valuesql select only highest valueget kth largest element sql dense rankselect second max salary from sqlsql highest nt14th highest salary sqlfind out the 2nd highest salary in sqlsecond highest salary codesecond highets value sqlsecond highest salary fastestsecond highest salary in sql using ranknth highest salary in sql serversql select second highest salarysql to find third highest salarynth maximum salary in sqlquery to find 2nd largest salary in sqlsecond highest in sqlhow to print highest salary in sqlselect second highest salary in sqlget nth salary sql serversql get the second highest valuefind n highest salary in sqlhow to write the inner query to get the max salrysql query how to find second highest salaryhow to fetch the second highest value from a tableslary table my sqlwrite a query to display second max salary of an employee 3fwrite an sql query to show the second highest salary from a table2nd height salary sqlnth highest salary queryfind second max salary query sqlsql query to find second highest salary with out using max 28 29 aggregator operator how to find the second max salary in sqlmax 2nd salary in sql querysql query to find nth highest salarysql select highest salaryselect the second highest salary in sql querymaximum salary in sqlhow to get 2nd and rd highest salary in sqlselect 2nd highest salary in mysqlfind second highest salary using limit in sqlwrite a sql query to find 2nd maximum salaryget kth largest element sql3rd highest salary in sql serverhow to fetch second highest number from a dataabasefind 3rd highest salary in sqlhighest nth salary in sqlsql find second max valuecreate a sql function to return nth highest salarywrite sql query to get the second highest salary among all employeeshow to find second largest salary in sqlsecond max salary query in sqlgive me a query to find out the second largest compensation in an organizationhighest salary in sqltop earning employee mysql querysql query to find nth largest salaryshallow last second salary in mysqlnth highest salary in mysqlhow to get fifth highest salary in sqlsecond highest salaryquery to find maximum salary of employee in sql4th highest salary in sqlwrite a query to find nth highest salaryhow to get second highest salary in sqlhow to get the 2nd highest salary in sqlsql second highest valuehow would you find the 10th highest employee salary in the employee table 3f2nd maximum salary in sql serverhighest salary in sq2 highest salary in sqlsql third highest salarynth highest salary in sql using ctehow to get highest salary in sql serverhow to highest salary in sqlselect 2nd highest salary from employee table in sqlsecond highest salary in sql