Mumbai Wadala Mumbai Wadala - 4 years ago 88
SQL Question

inner join on multiple columns in sql

i have two table


  • tbltask

  • tbluser



in tbl user i have two columns

userid and username

here i have

1 ibrahim

2 nizam

3 shahrukh

4 saddam


and in my second table i have multiple tasks

and columns are as follows

taskid, userid, assignby, assignto

1 4 4 2



here saddam assign a task to nizam


2 3 3 1



here shahrukh assign a task to ibrahim


i have a sekect command like

select userid, assignby, assignto from tbltask where taskid='1'


and i am getting this

3 3 1


now i want to join the table, because instead of i, i want username to be displayed

so answer which i want to display will be

shahrukh shahrukh ibrahim


how i can join the table?

Answer Source

Here is the query

Select  t2.username, t3.username, t4.username
From tbltask t1 inner join
tbluser as t2 on t1.userid = t2.userid inner join
Tbluser as t3 on t1.assignby = t3.userid inner join
Tbluser as t4 on t1.assignto = t4.userid
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download