Write a sql query to fetch the employees with same salary.

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

Great staff. Now how would I write the same for Microsoft SQL?

leratamotaung
Автор

select
e1.employee_name,
e2.employee_name,
e1.salary
from emp_salary e1
join emp_salary e2 on e1.salary = e2.salary
and e1 .employee_name < e2.employee_name;

KumarHemjeet
Автор

SELECT e1.EmployeeName, e2.EmployeeName
FROM Employees e1
JOIN Employees e2 ON
e1.Salary = e2.Salary AND e1.EmployeeID < e2.EmployeeID;
This whould work for the above problem.

maheshtiwari
Автор

You can also fetch either of two ways for same salaries employees but slightly performance hits (w/o use window function)
1)Select * from tablename
Where salary in ( select salary from(Select salary, count(*) as sal from tablename
Group by salary
Having count(*) >1))
Or
2)
Select e1. Eid, e1. Salary from emp e1 inner join emp e2
On e1. salary =e2.salary and e1. Eid<>e2.Eid

Tech.S