mysql排序相同值_MySQL如何排序具有相同值的行

bd96500e110b49cbb3cd949968f18be7.png

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

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?

解决方案

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

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值