# Find record of nth highest salary employee in SQL?

**Finding record of Nth highest salaried employee** (where N, should equal to records or less then of the records), Here we are finding 1st , 2nd, 3rd and so on highest salaried employee’s name one by one using SQL Query.

Here employee table, which has three fields **eid(employee id)**, **ename(employee name)**, **salary(employee salary)**.

Eid ename Salary 101 preeti 20000 102 apoorv 40000 103 antima 50000 104 rahul 10000 105 pankaj 5000

**Here, following queries being implemented:**

**1) Write a query to find name of 1 ^{st} highest salary employee from employee table?**

mysql> select ename from employee where salary = (select max(salary) from employee);

**Result:**

Ename Antima

**2) Write a query to find name of 2 ^{nd} highest salary employee from employee table?**

mysql> select ename from employee where salary = ( select max(salary) from employee where salary <( select max(salary) from employee));

**Result:**

Ename Apoorv

**3) Write a query to find name of 3 ^{rd} highest salary employee from employee table?**

mysql> select ename from employee where salary = ( select max(salary) from employee where salary <( select max(salary) from employee where salary <( select max(salary) from employee)));

**Result:**

Ename Preeti

**4) Write a query to find name of 4 ^{th} highest salary employee from employee table?**

mysql> select ename from employee where salary = ( select max(salary) from employee where salary <( select max(salary) from employee where salary <( select max(salary) from employee where salary < (select max(salary) from employee))));

**Result:**

Ename rahul

**5) Write a query to find name of 5 ^{th} highest salary employee from employee table?**

mysql> select ename from employee where salary = ( select max(salary) from employee where salary <( select max(salary) from employee where salary <( select max(salary) from employee where salary < (select max(salary) from employee where salary< (select max(salary) from employee)))));

**Result:**

Ename pankaj

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.