当前位置: 代码迷 >> Sql Server >> 怎么select 多个相同结构的表并把结果合并放在一起 .
  详细解决方案

怎么select 多个相同结构的表并把结果合并放在一起 .

热度:68   发布时间:2016-04-24 20:20:11.0
如何select 多个相同结构的表并把结果合并放在一起 ...
多个表相同结构的表,按天生成,如Table1001,Table1002, Table1003......

select * from table1001 where price > 10
select * from table1002 where price > 10
select * from table1003 where price > 10

是可以的,但这样的话,有几个表就存在几个结果,处理起来很麻烦。



select * from table1001, table1002, table1003 where price > 10

报错。

求助,怎样才能在一个语句中查询多个相同结构的表,并且把结果放在一个cursor里,看起来就象从一个表中查询出来的一样?
select 合并

------解决方案--------------------
select xxx from xxx where xxx
union all 
select xxx from xxxx where xxx
union all
select xxx from xxx where xxx
这样的格式
  相关解决方案