Search code examples
mysqlsqlsql-order-bysql-limit

How can execute limit first and then execute order by use mysql?


The flowing sql first execute order by reg_time and then execute limit but I want to first execute limit and after order by.who can tell me what to do.

select * from user where province = 'hai' order by reg_time limit 0,20;

Solution

  • Strange requirement, if you really really want that, you can try subquery:

    select *
    from (select * from user where province = 'hai' limit 0,20) t
    order by reg_time