显示两个表的资料
请怎么在MSSQL中怎么样列出两个表的资料
例:
表1
table1field1,table1field2,table1field3
1 23 11
2 33 12
2 11 8
表2
table2field1,table2field2
22 32
11 9
实现查询结果为
table1field1,table1field2,table1field3,table2field1,table2field2
1 23 11 <NULL> <NULL>
2 33 12 <NULL> <NULL>
2 11 8 <NULL> <NULL>
<NULL> <NULL> <NULL> 22 32
<NULL> <NULL> <NULL> 11 9
问题点数:50、回复次数:4Top
1 楼jinjazz(近身剪)回复于 2005-04-04 15:02:57 得分 5
怎么关联的呢?Top
2 楼chuxin1(华南)回复于 2005-04-04 15:03:58 得分 0
非得有关联字段吗?Top
3 楼paoluo(一天到晚游泳的鱼)回复于 2005-04-04 15:46:00 得分 45
那就这样试试。
--建立测试环境
Create table 表1
(table1field1 Int,
table1field2 Int,
table1field3 Int)
Create table 表2
(table2field1 Int,
table2field2 Int)
GO
--插入数据
Insert 表1 Values(1, 23, 11)
Insert 表1 Values(2, 33, 12)
Insert 表1 Values(2, 11, 8)
Insert 表2 Values(22, 32)
Insert 表2 Values(11, 9)
GO
--测试
Select *,Null As table2field1,Null As table2field2 from 表1
Union All
select Null As table1field1,Null As table1field2,Null As table1field3,* from 表2
--删除测试环境
Drop table 表1
Drop table 表2
--结果
/*
table1field1 table1field2 table1field3 table2field1 table2field2
1 23 11 NULL NULL
2 33 12 NULL NULL
2 11 8 NULL NULL
NULL NULL NULL 22 32
NULL NULL NULL 11 9
*/Top
4 楼chuxin1(华南)回复于 2005-04-04 16:46:57 得分 0
谢谢你们问题解决了~~~
采用paoluo(一天到晚游泳的鱼)的方法.Top




