SELECT DISTINCT是否暗示某种结果 [英] Does SELECT DISTINCT imply a sort of the results

查看:73
本文介绍了SELECT DISTINCT是否暗示某种结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SELECT查询中包括DISTINCT是否意味着应该对结果集进行排序?

Does including DISTINCT in a SELECT query imply that the resulting set should be sorted?

我不认为这样做,但是我正在寻找权威的答案(网络链接).

I don't think it does, but I'm looking for a an authoritative answer (web link).

我有这样的查询:

Select Distinct foo
From Bar

在oracle中,结果是不同的,但未按排序顺序.在Jet/MS-Access中,似乎需要做一些额外的工作来确保结果是分类的.我假设在这种情况下,oracle遵循规范,而MS Access超越了.

In oracle, the results are distinct but are not in sorted order. In Jet/MS-Access there seems to be some extra work being done to ensure that the results are sort. I'm assuming that oracle is following the spec in this case and MS Access is going beyond.

此外,有没有一种方法可以给表提示它应该在foo上排序(除非另有说明)?

Also, is there a way I can give the table a hint that it should be sorting on foo (unless otherwise specified)?

推荐答案

来自

如果指定了DISTINCT,则使TXA为从TX中消除冗余重复值的结果.否则,将TXA设为TX.

If DISTINCT is specified, then let TXA be the result of eliminating redundant duplicate values from TX. Otherwise, let TXA be TX.

...

4)如果未指定an,则Q行的顺序与实现有关.

4) If an is not specified, then the ordering of the rows of Q is implementation-dependent.

最终,真正的答案是DISTINCT和ORDER BY是SQL语句的两个独立部分.如果您没有ORDER BY子句,则根据定义,结果将不会特别排序.

Ultimately the real answer is that DISTINCT and ORDER BY are two separate parts of the SQL statement; If you don't have an ORDER BY clause, the results by definition will not be specifically ordered.

这篇关于SELECT DISTINCT是否暗示某种结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆