2016-11-28 1 views
0

2 개의 테이블이 있습니다.이 합류 된 목록을 MySQL에서 어떻게 선택합니까?

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

내가 직원과 이름 열을 선택하여 목록을 작성하고 싶습니다 t_sibling

t_family

ID  Employee 
A1  John 
A2  Gladys 

.

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 

것이 가능한가? 미리 감사드립니다.

참고 :
노조가 없어도됩니까? 그냥 조인. 노조에 속도 문제가 있습니다. 특히 데이터 백됩니다 수천

+0

이 질문을 확인하려면 다음과 같이 두 테이블에서 원하는 출력을 얻을 수있을 것입니다 그것의 열 이름으로 임직원의 결과? –

+0

@MahmoodRehman 글쎄, 상태 (NULL)가없는 경우 'Employee'로 변경하십시오. – Vahn

+0

유니온없이 할 수 있습니까? 그냥 조인. 노조에 속도 문제가 있습니다. 특히 데이터는 수십만 개가됩니다. – Vahn

답변

0

사용 노조 내가 출력을 생각

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 
관련 문제