user3697028
user3697028

Reputation: 23

Join two fields from one table to another

i have two table as follows

Table1

id   name   appid  modifiedappid
---  ---    ----   ------------
1    abc     1        2

Table2

id   apllicationName
--   ---------------
1       App1
2       App2

when join these two table i need the below result

Name   appname   Modifiedappname
-----  -------   ----------------
abc     app1      app2

Upvotes: 0

Views: 45

Answers (2)

Özgür ACAR
Özgür ACAR

Reputation: 31

Select t1.Name, t2.ApplicationName as appname, t3.ApplicationName as modifiedappname from Table1 t1
Left Outer Join Table2 t2
on t2.id= t1.id
Left outer Join Table2 t3
on t3.id=t1.id
group by t1.Name, t2.ApplicationName, t3.ApplicationName

Upvotes: 0

Pரதீப்
Pரதீப்

Reputation: 93694

You need to Join Table2 twice

select Name , 
       B.apllicationName as appname,
       C.apllicationName as Modifiedappname
from Table1 A
Left join Table2 B on A.appid  = B.id
Left join Table2 C on A.modifiedappid = C.id

Note : If the values of appid & modifiedappid in Table1 will always have entry in Table2 then you can change theLeft Outer Join to INNER JOIN

Upvotes: 2

Related Questions