将两个表列值添加到单个列中

时间:2015-09-02 12:54:54

标签: mysql

我有两张桌子

table1
------------
id_1 | name_1 | valu1
_____________________
1    | name1  | 3
2    | abc1   | 3
3    | xyz1   | 3

table2
________________

id_2 | name_2 | valu1
_______________________
1    | name2  | 3
2    | abc2   | 3
3    | xyz2   | 3

现在我需要一个结果表作为

derived_name | d_valu1
__________________________
name1        | 3
abc1         | 3
xyz1         | 3
name2        | 3
abc2         | 3
xyz2         | 3

如何使用MySQL查询获取此表。请帮忙

1 个答案:

答案 0 :(得分:0)

您应该可以使用UNION执行此操作,如下所示:

(SELECT name_1 as derived_name, valu1 as d_valu1 FROM table1)
UNION
(SELECT name_2 as derived_name, valu1 as d_valu1 FROM table2)