Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
An employee table with fields :SlNo,Ename,MgrID.


SlNo EName MgrId

1 A 2
2 B 3
3 C 1



Result should be:

EName MgrName

A B
C A


The Sql query for this Result?
Posted

SQL
SELECT A.EName as EName , B.EName as MgrName FROM employee A INNER JOIN employee B on A.SlNo = B.MgrId
 
Share this answer
 
v3
Comments
RoshInd 21-Sep-11 7:09am    
SELECT A.EName as EName , B.EName as MgrName FROM employee A INNER JOIN employee B on B.SIno= A.MgrID
Toniyo Jackson 21-Sep-11 7:12am    
I didn't get you?
Abhinav S 21-Sep-11 7:17am    
First answer. SO my 5.
Toniyo Jackson 21-Sep-11 7:27am    
Thanks :)
Have a look at the SQL Inner Join[^] and try writing a query.
If you still dont get a solution, post your query here and someone will help you.
 
Share this answer
 
SELECT A.EName as EName , B.EName as MgrName FROM employee A INNER JOIN employee B on B.SIno= A.MgrID
 
Share this answer
 
v2
SELECT A.EName,(Select Top 1 EName from Employee Where SlNo=A.MgrId) as MGR From Employee A
 
Share this answer
 

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