Select top statement ordering by non-unique column
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 th开发者_高级运维e output order of the rows in this case and what a select top statement would use. Is it just random?
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)
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.
精彩评论