Reputation: 13
I have a table emp with columns :-
empid empname mgrid doj
1 Steve 2 25-03-2019
2 Winter 3 26-04-2019
3 Summer 1 27-05-2019
4 Autumn 2 28-06-2019
and a table sal with columns :-
empid project salary
1 P1 1000000
2 P1 60000
3 P2 5000
4 P3 1000000
I want to list name of employees with same salary. Desired result :-
first_employee second_employee salary
Steve Autumn 1000000
What I tried to do is join emp table with sal and before that was trying to self join sal table. How can I achieve the desired results also is there a way to use union in order to get the results.
Upvotes: 1
Views: 2327
Reputation: 1270401
What if there are more than two employees with the same salary?
I would recommend group_concat()
:
select salary, group_concat(empname order by doj) as empnames
from emp
group by salary
having count(*) > 1;
Upvotes: 2