Reputation: 93
Hi I have created a query to find employee details and supervisor details of an organization now i want that every employees name should be repeated in the supervisor column also once. Means :
employee num Supervisor num
1 2
**1 1**
2 3
**2 2**
3 4
etc
The query i wrote to get employee number and supervisor num is :-
Select a.employee_num,a.supervisor_num
from managers a;
This query will just give me....
employee num Supervisor num
1 2
2 3
3 4
Any suggestion will be helpful :)
Upvotes: 1
Views: 2298
Reputation: 1202
You could try this:
(SELECT a.employee_num,
a.supervisor_num
FROM managers a)
UNION ALL
(SELECT DISTINCT a.employee_num,
a.employee_num AS supervisor_num
FROM managers a)
ORDER BY 1,2
The first query is just like the one you created. The second will add every employee as a manager. Ordering the whole union will create the resultset you want.
Upvotes: 2