当前位置: 代码迷 >> Sql Server >> 同时查询几个表SQL,该如何处理
  详细解决方案

同时查询几个表SQL,该如何处理

热度:84   发布时间:2016-04-27 16:58:54.0
同时查询几个表SQL
小弟想同时查询12个表每个显示的字段都不相同,最后要按照时间显示20条记录.请问这样的SQL怎么写!
小弟在这里谢谢了!!

------解决方案--------------------
select col1, col2 from tb1
union all
select col1, col2 from tb2
union all
...

------解决方案--------------------
select top 20 * from (select time,a,b from t1 union all select time,c,d from t2...) t order by time
------解决方案--------------------
用union
------解决方案--------------------
表结构相同的话用UNION ALL不同的话补上空字段.
  相关解决方案