有两个查询语句,如下:
select * from t where a<>'2'select * from t where b='false'现在想通过一条sql语句把上面两个语句查询到的结果合并到一个临时表#tem中,求该语句该如何写..先谢谢了。
select * from t where a<>'2'select * from t where b='false'现在想通过一条sql语句把上面两个语句查询到的结果合并到一个临时表#tem中,求该语句该如何写..先谢谢了。
select * into #tem from t where a <>'2' and b='false'
--or
select * into #tem from (
select * from t where a <>'2'
union
select * from t where b='false' )
select * from t where a <>'2'
union all
select * from t where b='false'
UNION ALLselect * from t where b='false'
insert into #temp
select * from t where b=false
select * into #tem
from
(select * from t where a <>'2'
union all
select * from t where b='false')tb
union
select * from t where b='false'
而UNION ALL只是简单的将两个结果合并后就返回。这样,如果返回的两个结果集中有重复的数据,那么返回的结果集就会包含重复的数据了。