读书人

把三个表联合查询的有关问题

发布时间: 2012-03-24 14:00:46 作者: rapoo

把三个表联合查询的问题
有三个表分别是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 table1union allselect productid from table2union allselect productid from table3
[解决办法]
SQL code
select distinct * from (select productid from table1union allselect productid from table2union allselect productid from table3) t 

读书人网 >SQL Server

热点推荐