MySQL LIMIT是在ORDER BY之前还是之后应用的? [英] Is MySQL LIMIT applied before or after ORDER BY?

查看:341
本文介绍了MySQL LIMIT是在ORDER BY之前还是之后应用的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MySQL处理查询时,哪个先出现?

Which one comes first when MySQL processes the query?

一个例子:

SELECT pageRegions
FROM pageRegions WHERE(pageID=?) AND(published=true) AND (publishedOn<=?)
ORDER BY publishedON DESC
LIMIT 1';

即使记录与修订日期时间不匹配,如果在ORDER BY之后应用了LIMIT,是否还会返回上次发布的pageRegion?

Will that return the last published pageRegion even if the record does not match the revision datetime IF LIMIT is applied after ORDER BY?

推荐答案

是的,它在ORDER BY之后.对于您的查询,您将获得记录的publishedOn最高的记录,因为您要订购DESC,从而使结果集中的最大值最大,然后从中选择第一个.

Yes, it's after the ORDER BY. For your query, you'd get the record with the highest publishedOn, since you're ordering DESC, making the largest value first in the result set, of which you pick out the first one.

这篇关于MySQL LIMIT是在ORDER BY之前还是之后应用的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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