Get another order after limit

后端 未结 1 1540
不知归路
不知归路 2021-02-19 04:14

Imagine I\'ve a table \'users\' with two fields: \'age\' and \'name\'. I want to retrieve the top ten older users and then I want this list of ten sorted by name.

Is it

1条回答
  •  终归单人心
    2021-02-19 04:42

    Use a subselect:

    SELECT * FROM
    (
        SELECT *
        FROM users
        ORDER BY age DESC
        LIMIT 10
    ) AS T1
    ORDER BY name
    

    The inner select finds the 10 rows you want to return, and the outer select puts them in the correct order.

    0 讨论(0)
提交回复
热议问题