我有几个union all的查询,因为现在数据有限,不知道哪一种速度更快:第一种:
select 需要的字段列 from t1 where 条件
union all
select 需要的字段列 from t1 where 条件
union all
select 需要的字段列 from t1 where 条件
union all
select 需要的字段列 from t1 where 条件第二种:select * from(
select 需要的字段列 from t1
union all
select 需要的字段列 from t1
union all
select 需要的字段列 from t1
union all
select 需要的字段列 from t1)
as a where 条件条件都是一样的,不知道在理论上第一种和第二种哪一种更快?
谢谢!
select 需要的字段列 from t1 where 条件
union all
select 需要的字段列 from t1 where 条件
union all
select 需要的字段列 from t1 where 条件
union all
select 需要的字段列 from t1 where 条件第二种:select * from(
select 需要的字段列 from t1
union all
select 需要的字段列 from t1
union all
select 需要的字段列 from t1
union all
select 需要的字段列 from t1)
as a where 条件条件都是一样的,不知道在理论上第一种和第二种哪一种更快?
谢谢!
看一下,语句运行时间
set startistics io on
----语句
set startistics io off
declare @t1 datetime,@t2 datetime
select @t1=getdate()select * from sysobjectsselect @t2=getdate()select @t1,@t2自己做个时间测试。
set statistics io on
--
set statistics io off