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

存储过程中,如何把多个select结果,合并成一个结果集返回

2012-05-28 
存储过程中,怎么把多个select结果,合并成一个结果集返回?select userid,username,price,vol from table_a

存储过程中,怎么把多个select结果,合并成一个结果集返回?
select userid,username,price,vol from table_a ...
select userid,username,price,vol from table_b...


要让这两句形成一个结果集。怎么办?

[解决办法]
select userid,username,price,vol from table_a ...
union all
select userid,username,price,vol from table_b...

[解决办法]

SQL code
select userid,username,price,vol from table_a ...union all--不去掉上下两语句的重复行select userid,username,price,vol from table_b...select userid,username,price,vol from table_a ...union--去掉上下两语句的重复行select userid,username,price,vol from table_b...
[解决办法]
select userid,username,price,vol from table_a ...
union all
select userid,username,price,vol from table_b...
 

热点排行