Search
 
SCRIPT & CODE EXAMPLE
 

SQL

How to find third highest salary in SQL

-- creating Employee table in Oracle
CREATE TABLE Employee (name varchar(10), salary int);

-- inserting sample data into Employee table
INSERT INTO Employee VALUES ('Rick', 3000);
INSERT INTO Employee VALUES ('John', 4000);
INSERT INTO Employee VALUES ('Shane', 3000);
INSERT INTO Employee VALUES ('Peter', 5000);
INSERT INTO Employee VALUES ('Jackob', 7000);

SELECT TOP 1 salary 
FROM (
  SELECT DISTINCT TOP 3 salary FROM Employee ORDER BY salary DESC 
  ) AS temp 
ORDER BY salary
Comment

query to find second highest salary

SELECT MAX(SALARY) FROM Employee WHERE SALARY < (SELECT MAX(SALARY) FROM Employee)
Comment

query to find third highest salary

-*FOR THIRD HIGHEST SALARY*

Select top 1 from (select top 3 salary from emp order by salary desc)
order by asc
Comment

PREVIOUS NEXT
Code Example
Sql :: python get backup of sql 
Sql :: sql like case sensitive 
Sql :: psql shell 
Sql :: ImportError: DLL load failed while importing _sqlite3: The specified module could not be found. 
Sql :: mysql decimal remove trailing zeros 
Sql :: sqlite modify row 
Sql :: mysql create pool 
Sql :: how to recreate postgres database in docker 
Sql :: how to use query in nosql 
Sql :: double in sql server example 
Sql :: docker hub mysql 
Sql :: mssql remove duplicate rows 
Sql :: how to get table id sequence postgres 
Sql :: sql describe 
Sql :: mysql count 
Sql :: pgadmin check database 
Sql :: sql numeric data type 
Sql :: trigger sql 
Sql :: how to check which table has data in mysql 
Sql :: copy data from one postgres container to another 
Sql :: stored procedure data to table 
Sql :: in in sql 
Sql :: sqlalchemy query sql compiled 
Sql :: SQL Greater than () 
Sql :: sql union 
Sql :: max mysql 
Sql :: sql asc 
Sql :: update sql 
Sql :: description query in sql 
Sql :: what does leave do in mysql 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =