如何在MySQL中选择此连接列表

时间:2016-11-28 04:54:52

标签: php mysql

我有2张桌子。

t_family

ID     Employee   
A1     John
A2     Gladys

t_sibling

ID     Name       Status
A1     Darco      Brother
A1     Carmen     Sister
A1     Clara      Sister
A2     Luther     Brother

我想通过选择员工和姓名列来制作一个列表。

SELECT (this code i'm looking for) AS Family, Status from t_family INNER JOIN t_sibling ON t_family.ID = t_sibling.ID

输出

Family      Status
John        Employee
Darco       Brother
Carmen      Sister
Clara       Sister
Gladys      Employee
Luther      Brother

有可能吗?提前谢谢。

注意:
没有工会我能做到吗?只是一个加入。我和工会有速度问题。特别是数据将是数十万。

1 个答案:

答案 0 :(得分:0)

使用union从两个表中获取所需的输出,如下所示

select Employee as Name,status 
from 
(
select id,Employee ,'Employee 'as status from t1

union all

select id,Name,status from t2
)
order by id asc