简体   繁体   English

SQL:从其他表中读取列的描述

[英]SQL: Reading description for a columns from a different table

I have a table (T1) with two columns (C1, C2) that describes the relationship between a parent group and child group. 我有一个表(T1),其中两列(C1,C2)描述了父组和子组之间的关系。 But this relation ship is defined based on group id. 但是,此关系是基于组ID定义的。 The name of the group is defined in another table (say T2). 组的名称在另一个表中定义(例如T2)。

Eg: T1 has below values. 例如:T1具有以下值。 C1 is for Parent Group Id and C2 is for Child Group Id. C1用于父组ID,C2用于子组ID。 I have three groups in following order 1 - 2 - 3. 我按以下1-2-3的顺序分为三组。

C1,C2
1,2
2,3

T2 has below values T2的值低于

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. 现在,我需要通过SQL查询合并上面的表格,这样我就可以得到下面的输出。

C1,C2
Parent_Group,Child_Group1
Child_Group1,Child_Group2

How can i achieve the same? 我怎样才能达到同样的目的?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM