Reputation: 453
I have a table (T1) with two columns (C1, C2) that describes the relationship between a parent group and child group. But this relation ship is defined based on group id. The name of the group is defined in another table (say T2).
Eg: T1 has below values. C1 is for Parent Group Id and C2 is for Child Group Id. I have three groups in following order 1 - 2 - 3.
C1,C2
1,2
2,3
T2 has below values
C1,C2
1,Parent_Group
2,Child_Group1
3,Child_Group2
Now, I need to combine above table via SQL query, so that i will get below output.
C1,C2
Parent_Group,Child_Group1
Child_Group1,Child_Group2
How can i achieve the same?
Upvotes: 1
Views: 41
Reputation: 16140
Try this:
SELECT
C1.C2 AS C1, C2.C2 AS C2
FROM
T1 INNER JOIN
T2 C1 ON T1.C1 = C1.C1 INNER JOIN
T2 C2 ON T1.C2 = C2.C1
Upvotes: 2