Horje
sql find second highest salary employee Code Example
sql select second max
Both options you find max as a subset and then exclude from main select
sql> SELECT MAX( col ) FROM table
 	WHERE col < ( SELECT MAX( col ) FROM table);
sql> SELECT MAX(col) FROM table 
WHERE col NOT IN (SELECT MAX(col) FROM table);
sql find second highest salary employee
/* sql 2nd highest salary employee */
select sal, ename
from emp
where sal =
    (
        select max(sal) from emp where sal <
            (select max(sal) from emp)
    )
----------------------------------------------- option 2
select *
from 
(
    select ename, sal, dense_rank() over(order by sal desc) rank
    from emp
)
where rank =2;
sql highest salary by location
/*  Highest salary by Department/Location   */
SELECT e.ename, e.sal, e.deptno, d.loc
FROM emp e
JOIN dept d
ON e.deptno = d.deptno
WHERE e.sal in
( 	
  	select max(sal) 
  	from emp 
  	group by deptno
)




Sql

Related
sql select from multiple tables without join Code Example sql select from multiple tables without join Code Example
alter column to not null with default value sql server Code Example alter column to not null with default value sql server Code Example
auto increment column in mysql query results Code Example auto increment column in mysql query results Code Example
gremove folder from git Code Example gremove folder from git Code Example
oracle grant on all tables in schema Code Example oracle grant on all tables in schema Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7