SQL Server :
http://www.dotnet-tricks.com/Tutorial/sqlserver/SQ23310812-Get-nth-highest-and-lowest-salary-of-an-employee.html
SELECT e1.EmpId, e1.EmpName FROM EmployeeDetails e1, EmployeeDetails e2 where e1.EmpId=e2.ManagerId;
Now if I want get the details of Empolyees who are in Manager Position for that we need to write query like this
Query to get nth(3rd) Highest Salary
- Select TOP 1 Salary as '3rd Highest Salary'
- from (SELECT DISTINCT TOP 3 Salary from Employee ORDER BY Salary DESC)
- a ORDER BY Salary ASC
http://www.dotnet-tricks.com/Tutorial/sqlserver/SQ23310812-Get-nth-highest-and-lowest-salary-of-an-employee.html
Self Join
Joining the table itself called self join. Self join is
used to retrieve the records having some relation or similarity with other
records in the same table. Here we need to use aliases for the same table to
set a self join between single table and retrieve records satisfying the
condition in where clause.
SELECT e1.EmpId, e1.EmpName FROM EmployeeDetails e1, EmployeeDetails e2 where e1.EmpId=e2.ManagerId;
Now if I want get the details of Empolyees who are in Manager Position for that we need to write query like this
nice
ReplyDeleteour pleasure
Delete