third highest salary from employees table

 


To find the third highest salary from the Employee table in SQL, you can use the ORDER BY clause in combination with LIMIT. Here's an example query assuming you have an Employee table with a "Salary" column:
SELECT DISTINCT Salary
FROM Employee
ORDER BY Salary DESC
LIMIT 2, 1;

Explanation:

  • ORDER BY Salary DESC: This sorts the salaries in descending order, so the highest salary is at the top.
  • LIMIT 2, 1: This skips the first two highest salaries (offset 2) and then fetches the next salary (limit 1), which is effectively the third highest salary.

If you want to handle cases where there are fewer than three distinct salaries (e.g., only one or two distinct salaries exist), you can modify the query to include error handling or adjust the logic based on your specific requirements.

No comments:

Post a Comment

React -1 ( react with ravenndra kanchi)

 react with tool chanis 45 to 50 sessions core  after 50 sessions -> some tooll chains == react with type script mern stackaplication in ...