读书人

数据库查询有关问题

发布时间: 2012-01-30 21:15:58 作者: rapoo

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

读书人网 >C#

热点推荐