Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear sir i have two table one is DepartmentUser and Second is TransferDetail
DepartmentUser is having following data

HTML
DUID	Fname	Lname	DOB	       Address
1	Jitendra Gupta	1/1/1998	N-12 
2	Veeru	gupta	1/3/1995	s-56

and

TransferDetail

HTML
TID  TransferByFrom  TransferByTo   Date
1      1(DUID)             2(DUID)         1/1/2015
2      2 (DUID)            1(DUID)          5/7/2015



Now i want result IN form of using sql

HTML
TID  TransferByFrom  TransferByTo   Date
1       Jitendra(Fname)           Veeru(Fname)         1/1/2015
2      Veeru(Fname)             Jitendra(Fname)        5/7/2015



please help to do this.


thanks advance...
Posted
Updated 26-Jan-15 23:06pm
v4
Comments
[no name] 27-Jan-15 5:59am    
What ever you had asked here, your question itself contains the solution. Read some concepts of join and follow the best option based on your requirement.

Hello ,
you have to make join between above given tables .
SELECT A.TID,B.FNAME,C.FNAME,A.date FROM TransferDetail  A INNER JOIN DepartmentUser  B ON A.TransferByFrom =B.DUID INNER JOIN DepartmentUser C ON A.TransferByTo=C.DUID


thanks
animesh
 
Share this answer
 
Comments
osmo33 27-Jan-15 6:18am    
Thanks..........
Animesh Datta 27-Jan-15 6:22am    
welcome
Make two left joins on TransferDetail with DepartmentUser one for the key TransferByFrom and 2nd for the key TransferByTo

As below


SQL
select  TID, TransferByFrom=frm.fname, TransferByTo=To.Fname,Date
from TransferDetail TD 
Left Join  DepartmentUser frm On TD.TransferByFrom=frm.DUID
Left Join  DepartmentUser To On TD.TransferByTo=To.DUID
 
Share this answer
 
Comments
Pr@n@v-BiTwiser 27-Jan-15 4:14am    
instead you can use Full Outer Join...:)

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