Search
 
SCRIPT & CODE EXAMPLE
 

SQL

write sql query to find the second highest salary of employee

SELECT MAX(Salary) From Employee
 WHERE Salary < ( SELECT Max(Salary) FROM Employee);
Comment

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

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;
Comment

2nd max salary query in sql

select *from employee 
group by salary 
order by  salary desc limit 1,1;
Comment

nth highest salary in sql

Here is the solution for nth highest
salary from employees table 

SELECT FIRST_NAME , SALARY FROM 
(SELECT FIRST_NAME, SALARY, DENSE_RANK() OVER
(ORDER BY SALARY DESC) AS SALARY_RANK
FROM EMPLOYEES)
WHERE SALARY_RANK = n; 
Comment

nth highest salary in sql

select * from(
select ename, sal, dense_rank() 
over(order by sal desc)r from Employee) 
where r=&n;

To find to the 2nd highest sal set n = 2
To find 3rd highest sal set n = 3 and so on.
Comment

nth 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 N salary FROM Employee ORDER BY salary DESC 
  ) AS temp 
ORDER BY salary
*/

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


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

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

PREVIOUS NEXT
Code Example
Sql :: to_date postgresql 
Sql :: mysql not equal 
Sql :: postgres default value 
Sql :: download sql server for mac 
Sql :: sql Split string function 
Sql :: mysql default value 
Sql :: sql use not in 
Sql :: sql server change column data type 
Sql :: oracle parameter 
Sql :: sqlite3 pragma foreign keys 
Sql :: auto increment column in mysql query results 
Sql :: tablas bootstrap responsive sql server para datos vivos 
Sql :: calculate date and convert to yearsmysql 
Sql :: creating sqeuence in oracle database 
Sql :: find log file postgresql linux 
Sql :: sql example query 
Sql :: change schema in sql server 
Sql :: alter column to not null with default value sql server 
Sql :: how to casting data types in postgresql 
Sql :: linux bash run sql command 
Sql :: start and stop mysql 
Sql :: postgres having 
Sql :: sql where not like in list 
Sql :: datagrip exec 
Sql :: sql select whole row max column 
Sql :: sql composite key 
Sql :: replace content value from old to new sql 
Sql :: SQL Query to delete all the tables in a database 
Sql :: timestamp sql 
Sql :: pgadmin postgres ERROR: database is being accessed by other users 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =