三個查詢結果相同的SQL語句,那個效率更高

今年天拿論壇上一個問題,讓我更多瞭解一下SQL時間函數。

 

 

 

 

問題在大量數據的情況下 比較下面那個數據查詢語句的效率高

 

select id  from table_a where table_a.id in (select table_b.id from table_b where table_a.id=table_b.id)

select table_a.id from Ttable_a,table_b where table_a.id=table_b.id

select table_a.id from table_a left outer join table_b on table_a.id=table_b.id


答:用查詢用的時間做對比

 

1.用MSSQL2000的數據查詢分析器

 

DECLARE @begin datetime 
DECLARE @chaju int
DECLARE @end datetime 
set @begin=getdate()

**********上面的三個select 語句之一 ********


set @end=getdate()
SELECT @chaju = datediff(Millisecond, @begin, @end) 
print @chaju

 

@chaju 用時多少毫秒

-------------------------------------------------------------------------------------------------------------------------

 

2用SYBASE數據庫 SQL Advantage工具

 

DECLARE @begin_time datetime
SELECT @begin_time  =getdate()
Select CONVERT(varchar(100), getdate(), 8)


**********上面的三個select 語句之一 ********

go

DECLARE @end_time datetime
SELECT @end_time =getdate()
Select CONVERT(varchar(100), getdate(), 8)
go

 

可以查出時間 只精確到秒。

 

 

大家有興趣的也可以參與進來,一起討論這個問題。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值