简体   繁体   English

按非唯一列选择顶部语句的排序

[英]Select top statement ordering by non-unique column

I have two sql queries 我有两个SQL查询

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. Column1是非唯一列,而table1没有主键。

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. 我想知道普通的SELECT语句在这种情况下使用哪种方法确定行的输出顺序,以及select top语句将使用什么方法。 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) 相反,强加您想要的顺序(通过在ORDER BY中包括其他列)

认为它是随机的-即使在某些情况下它不是随机的,如果联系少于ORDER BY要求的排序,则DBMS也不应该对结果的排序作出保证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM