MySQL如何排序具有相同值的行 [英] How mysql order the rows with same values

查看:506
本文介绍了MySQL如何排序具有相同值的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库中,我有一些记录,在这些记录中,我按正好是相同的值进行排序:

In my database I have some records where I am sorting by what happens to be the same value:

| col1 | timestamp              |
| row1 | 2011-07-01 00:00:00    |
| row2 | 2011-07-01 00:00:00    |
| row3 | 2011-07-01 00:00:00    |

SELECT ... ORDER BY timestamp

结果似乎是随机顺序的. 随机顺序是否一致?这意味着如果我在两个mysql服务器中有这些数据.我能期望得到相同的结果吗?

It looks like the result is in random order. Is the random order consistent? That means if I have these data in two mysql servers.Can I expect the same result?

推荐答案

我建议不要做这个假设.在标准SQL中,显式ORDER BY子句不需要的所有内容都取决于实现.

I'd advise against making that assumption. In standard SQL, anything not required by an explicit ORDER BY clause is implementation dependent.

我不能代表MySQL,但是例如SQL Server,就ORDER BY而言,相等"的行的输出顺序在每次查询运行时可能会有所不同-并可能受到几乎任何因素的影响(例如服务器的补丁程序/服务包级别,工作量,当前在缓冲池中的页面等).

I can't speak for MySQL, but on e.g. SQL Server, the output order for rows that are "equal" so far as the ORDER BY is concerned may vary every time the query is run - and could be influenced by practically anything (e.g. patch/service pack level of the server, workload, which pages are currently in the buffer pool, etc).

因此,如果您需要一个特定的订单,则您可以做的最好的事情(既要保证它,又要为将来的维护者记录您的查询)是显式地请求您想要的订单.

So if you need a specific order, the best thing you can do (both to guarantee it, and to document your query for future maintainers) is explicitly request the ordering you want.

这篇关于MySQL如何排序具有相同值的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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