Is MySQL LIMIT applied before or after ORDER BY?

后端 未结 3 2074
孤街浪徒
孤街浪徒 2020-12-28 12:50

Which one comes first when MySQL processes the query?

An example:

SELECT pageRegions
FROM pageRegions WHERE(pageID=?) AND(published=true) AND (publis         


        
3条回答
  •  星月不相逢
    2020-12-28 13:12

    The limit is always applied at the end of result gathering, therefore after order by.

    Given all your clauses, the order of processing will be

    • FROM
    • WHERE
    • SELECT
    • ORDER BY
    • LIMIT

    So you will get the closest record <= publishedOn matching all the conditions in the WHERE clause.

提交回复
热议问题