views:

21

answers:

2

I have two sql queries

select * from table1
ORDER BY column1

Select top 10 * from table1
ORDER by column1

Column1 is a non unique column and table1 does not have a primary key.

When I run both queries, I'm getting the rows returning in different orders. I attribute this to the fact that the criterion for ranking (the Order By) is non unique.

I'm wondering what method does a normal SELECT statement use to determine the output order of the rows in this case and what a select top statement would use. Is it just random?

+2  A: 

In the non-unique case, the output order of the rows should not be relied upon.

Instead, impose the ordering you want (by including other columns in the ORDER BY)

Mitch Wheat
+1, not least for the suggestion of additional columns in the ORDER BY.
Will A
+1  A: 

Consider it random - even if it isn't in some circumstances, no DBMS should be making promises on the ordering of results in the case of ties short of the ordering requested by ORDER BY.

Will A