MySQL的LIMIT关键字保证返回数据的顺序吗? [英] Does MySQL's LIMIT keyword guarantee order of returned data?

查看:889
本文介绍了MySQL的LIMIT关键字保证返回数据的顺序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的MySQL,但我已经使用Oracle一段时间。我对MySQL的 LIMIT 关键字有点困惑。此关键字是否意味着每次执行查询时返回的数据的顺序是否相同?如果更多的数据被添加到影响查询的表中怎么办?

I am new to MySQL, but I have used Oracle for some time. I am a little confused about MySQL's LIMIT keyword. Does this keyword imply that the order of the returned data will be the same every time the query is executed? What if more data is added to the tables that affect the query? And how would the data be ordered if no order-by clause exists?

推荐答案

不, LIMIT 是非确定性的。顺序取决于数据,使用什么索引,mysql版本之间的内部变化,磁盘上的数据顺序等。

No, LIMIT is non-deterministic. The ordering depends on the data, what indexes are used, internal changes between mysql versions, order of data on disk etc.

通常你会组合 LIMIT ORDER BY ,以避免这种情况。

Usually you'd combine LIMIT with an ORDER BY to avoid this.

这篇关于MySQL的LIMIT关键字保证返回数据的顺序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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