sql - Which Select query will run faster -


this question has answer here:

hi trying maximum id table has approx 1 million records. please suggest me on of these query execute faster.

option 1:

select top 1 surveyuserresponseid surveyuserresponse order surveyuserresponseid desc 

option 2:

select max(surveyuserresponseid) surveyuserresponse 

as per actual execution plan both query took same time execute.

you can try yourself. run query time statistics. so:

set statistics time on; select top 1 surveyuserresponseid surveyuserresponse order surveyuserresponseid desc set statistics time off; 

and see on "messages" tab how long took execute each query.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -