If you have a table in SQL Server with name of “employee” and column names of “eno, ename, salary, dno, managerID. The employee table is as following.
If you are writing a query To Get Top 2 Highest Salary Employee Details as follows
then the Output is as follows.
You can clearly observe that the output is incorrect for Top 2 Highest Salary Employee Details In a SQL Server Table. Because if you are not given order by query then top 2 query by default takes least values from employee table.
So now you can write query by using Order by as follows
Now you can see the output, it matches to your question - SQL Query To Get Top 2 Highest Salary Employee Details In A SQL Server Table?.
But this is also not a full answer, because it shows only top2 salary. It will not show employee details. So to get employee details who have top 2 highest salary, write query as
Select * from employee where salary in (
Select top 2 salary from employee order by salary desc
Now you can see the output in the following table
So here you can get the exact answer for “How to write SQL Query To Get Top 2 Highest Employee Details In A SQL Server Table”.
Conclusion: If you any Queries related to “How to write SQL Query To Get Top 2 Highest Employee Details In A SQL Server Table”. Then comment here, we are ready to help you.
You May also search in Google as:
Freshers Junction – SQL Query for top 2 highest salary employee details, SQL query to two highest salary employee details, top 2 employee salary details in SQL Server, SQL Server Query to get Top 2 Highest Employee Details In A SQL Server Table. Top 2 values in SQL Server.