How can I fetch a particular piece of information from an SQL database?

187    Asked by Aalapprabhakaran in SQL Server , Asked on Jan 4, 2024

 I am currently working with an employee database in which I need to retrieve the 3rd highest salary from the table of “Employee”. How can I construct an SQL query for fetching this particular piece of information from the database? 

 In the context of your scenario under SQL, if you want to fetch 3rd max salary in SQL, then follow several points which are given below:-

You can use the following SQL query for this purpose:-

SELECT DISTINCT Salary 
FROM Employees
ORDER BY Salary DESC
OFFSET 2 ROWS FETCH NEXT 1 ROpurpose
SELECT DISTINCT salary values
Specify the table “employees” FROM Employees

Order the salaries in descending or ascending order (descending in your case) by using ORDER BY salary DESC.

OFFSET 2 ROWS FETCH NEXT ROW ONLY: you can skip the first two rows to get the 3rd highest salary value.



Your Answer

Interviews

Parent Categories