首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

数据库查询有关问题

2012-01-30 
数据库查询问题在线等table1有字段A,B,table2有字段C,Dselecta,bfromtable1wherea1selectc,dfromtable2wh

数据库查询问题 在线等
table1有字段A,B,
table2有字段C,D
select   a,b   from   table1   where   a   =   1
select   c,d   from   table2   where   c   =2
这两条语句能不能写在一条查询语句里   做为一个结果集合返回

[解决办法]
(select a,b from table1 where a = 1)
union
(select c as a,d as b from table2 where c =2)
[解决办法]
如果

table1有字段A,和 table2有字段C

table1有字段B,和 table2有字段D

类型是一致.

这样就可以了
select a,b from table1 where a = 1
union all
select c,d from table2 where c =2

热点排行