I have two tables usrTable and testTable.
u_id usr
----------- ------------
1 sa
2 bob
3 john
t_id usr1 usr2 usr3
---------- ---------- ---------- ----------
1 1 1 2
2 1 2 2
3 2 3 3
4 1 2 3
Now I want to join this tables together so that instead of showing the id of each usr it will show the name...so the result I'm looking for is:
t_id usr1 usr2 usr3
----------- ----------- ----------- -----------
1 sa sa bob
2 sa bob bob
3 bob john john
4 sa bob john
But I don't know how to write a query that givs me that result.
If it only whare one usr col in testTable then a simple Inner join like this whould work:
t_id usr
------ -------
1 sa
2 sa
3 bob
4 sa
I have tested diffrent kinds of joins and the UNION operator but I don't manage to get the result I'm looking for. Please help me.
Code:
select * from usrTable
u_id usr
----------- ------------
1 sa
2 bob
3 john
Code:
select * from testTable
---------- ---------- ---------- ----------
1 1 1 2
2 1 2 2
3 2 3 3
4 1 2 3
Now I want to join this tables together so that instead of showing the id of each usr it will show the name...so the result I'm looking for is:
t_id usr1 usr2 usr3
----------- ----------- ----------- -----------
1 sa sa bob
2 sa bob bob
3 bob john john
4 sa bob john
But I don't know how to write a query that givs me that result.
If it only whare one usr col in testTable then a simple Inner join like this whould work:
Code:
select testTable.t_id, usrTable.usr from testTable inner join usrTable on testTable.usr1 = usrTable.u_id
------ -------
1 sa
2 sa
3 bob
4 sa
I have tested diffrent kinds of joins and the UNION operator but I don't manage to get the result I'm looking for. Please help me.