日期:2014-05-18  浏览次数:20449 次

把三个表联合查询的问题
有三个表分别是table1,table2,table3,三个表都有一个字段为productid

table1的productid的值为
G0001
G0002
G0003

table2的productid的值为
G0004
G0005
G0006

table3的productid的值为
G0007
G0008
G0009

我现在想通过一句查询命令,把三个表联合查询,得出以下结果:
G0001
G0002
G0003
G0004
G0005
G0006
G0007
G0008
G0009

请问应该如何实现,谢谢

------解决方案--------------------
SQL code
select productid from table1
union all
select productid from table2
union all
select productid from table3

------解决方案--------------------
SQL code
select distinct * from 
(
select productid from table1
union all
select productid from table2
union all
select productid from table3
) t