MySQL如何处理查询中的ORDER BY和LIMIT? [英] How does MySQL process ORDER BY and LIMIT in a query?

查看:205
本文介绍了MySQL如何处理查询中的ORDER BY和LIMIT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下查询:

SELECT article FROM table1 ORDER BY publish_date LIMIT 20

ORDER BY如何工作?是先排序所有记录,然后获取前20条记录,还是先获取20条记录,然后按publish_date字段对其进行排序?

How does ORDER BY work? Will it order all records, then get the first 20, or will it get 20 records and order them by the publish_date field?

如果是最后一篇,则不能保证您会真正获得最新的20篇文章.

If it's the last one, you're not guaranteed to really get the most recent 20 articles.

推荐答案

它将首先排序,然后获取前20.数据库还将处理ORDER BY之前的WHERE子句中的任何内容.

It will order first, then get the first 20. A database will also process anything in the WHERE clause before ORDER BY.

这篇关于MySQL如何处理查询中的ORDER BY和LIMIT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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