1

Hi I am trying to get maximum ID from a table which has approx 1 million records. Please suggest me which on of these query will execute faster.

Option 1:

select top 1 SurveyUserResponseID from surveyuserresponse order by SurveyUserResponseID desc

Option 2:

select max(SurveyUserResponseID) from surveyuserresponse

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

Amit Mishra
  • 431
  • 5
  • 16
  • 2
    *If you have two horses and you want to know which of the two is the faster then **race your horses*** - see [Which is faster?](http://ericlippert.com/2012/12/17/performance-rant/) by Eric Lippert for more background – marc_s Dec 02 '14 at 07:42

2 Answers2

2

You can try it by yourself. Run your query with time statistics. Like so:

set statistics time on;
select top 1 SurveyUserResponseID from surveyuserresponse order by SurveyUserResponseID desc
set statistics time off;

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

Ivan Sivak
  • 7,178
  • 3
  • 36
  • 42
0

Hi I am trying to get maximum ID from a table which has approx 1 million records. Please suggest me which on of these query will execute faster.

As per yourself they'll both take the same time:

both query took same time to execute.

Therefore neither query will be faster than the other.

ta.speot.is
  • 26,914
  • 8
  • 68
  • 96