假设我有两个具有相同列的表
tblfamilyHead
id f_name mi l_name address
1 Dizon T. Gomez Canada
2 Edgar R. Curtis California
tblfamilyMember
id headid f_name mi l_name address
1 1 michael A. Gomez Canada
2 1 Sharon A. Gomez Canada
3 2 Curt C. Curtis California
我希望得到预期的结果如下:
id f_name mi l_name address
1 Dizon T. Gomez Canada
2 Edgar R. Curtis California
1 michael A. Gomez Canada
1 Sharon A. Gomez Canada
2 Curt C. Curtis California
请帮我解决这个问题。谢谢。
答案 0 :(得分:0)
使用UNION ALL
设置运算符:
SELECT id
, f_name
, mi
, l_name
, address
FROM tblfamilyHead
UNION ALL
SELECT headid Id
, f_name
, mi
, l_name
, address
FROM tblfamilyMember
答案 1 :(得分:0)
您可能会像
一样匆匆到UNION ALL
表
select id, f_name, mi, l_name, address from tblfamilyHead
union all
select headid, f_name, mi, l_name, address from tblfamilyMember
答案 2 :(得分:0)
使用UNION组合2个具有相同列数的表:
SELECT a,b,c FROM table1
UNION
SELECT a,b,c FROM table2