日期:2014-05-20  浏览次数:20621 次

数据库查询问题 在线等
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