What is faster request (select a name .... or select a name (1) at the top

What is a quick request?

select Name from Worker

or

select TOP(1) Name from Worker

I have 1,000,000 entries

Thanks in advance

+3
source share
1 answer

If you don't have ORDER BY or DISTINCT, SELECT TOP(1) Name FROM Workerit’s faster.

The reason for this is that if you have ORDER BY or DISTINCT, the query must go through the entire table to sort and filter unwanted results. If this is a direct SELECT TOP, he can go to the first page, take the first row and do it very quickly.

+9
source

Source: https://habr.com/ru/post/1710349/


All Articles