This project is read-only.

SELECT Sales.Customer



I'm no expert in sql but can someone explain to me why do I get different CustomerID list with these two queries:


SELECT TOP 1000 [CustomerID]
  FROM [AdventureWorks2012].[Sales].[Customer]


SELECT TOP 1000 [CustomerID]
   FROM [AdventureWorks2012].[Sales].[Customer]
Thanks for helping!

file attachments


kevriley wrote May 16, 2014 at 4:21 PM

You are specifying top 1000, but with no ORDER BY clause, so essentially you are getting 1000 random rows.

The difference in execution plans means that you get a different 1000 rows.
The first query is a clustered index scan, the second a non-clustered index scan.

vikash_nda wrote Jul 10, 2014 at 5:34 PM

logically the results are same the only difference is the order they are shown to you. when you order by the second query you will see the same result. SInce the order by clause executes after select there is no chances of data being rearranged in both the cases.

wrote Jul 10, 2014 at 5:35 PM