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