首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-03-24 
把三个表联合查询的问题有三个表分别是table1,table2,table3,三个表都有一个字段为productidtable1的produ

把三个表联合查询的问题
有三个表分别是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 

热点排行