Click here to Skip to main content
15,905,233 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
ihave a table named employee contain value
VB
eid name  Manager type
1   Mike    3     1
2   David   3     2
3   Roger   NULL
4   Marry   2     1
5   Joseph  2     2

It is fixed that a manager has only 2 Employee
i want to write a query which produce result like below
VB
Manager   Employe1  Employee2
roger     Mike       David
David     Joseph     Marry     


thanks in advance
Posted
Updated 12-Dec-12 19:13pm
v2

1 solution

Try
SQL
SELECT M.Name AS Manager, Employe1, Employe2
FROM
(
SELECT Name, eID FROM Employee
WHERE eID IN (SELECT Manager FROM Employee)
) M
INNER JOIN
(
    SELECT Name AS Employe1, Manager,Type
    FROM Employee
    WHERE Type = 1
) E1 ON M.eID = E1.Manager
INNER JOIN
(
    SELECT Name AS Employe2 , Manager,Type
    FROM Employee
    WHERE Type = 2
) E2 ON M.eID = E2.Manager
 
Share this answer
 
Comments
rajin kp 13-Dec-12 1:47am    
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900