Order MySQL Query By Random and field?

I am trying to find a way to pull 10 random records and then order these 10 records by field. I tried the following:

SELECT name FROM users ORDER BY RAND (), name LIMIT 10

but it does not sort by name with 10 rows returned, it simply returns 10 random records in any order. Is there a way to sort by rand () and field inside a query with MySQL?

+3
source share
2 answers

Ended up just doing sorting in php.

+1
source
SELECT  name
FROM    (
        SELECT  name
        FROM    users
        ORDER BY
                RAND()
        LIMIT 10
        ) q
ORDER BY
        name
+8
source

Source: https://habr.com/ru/post/1771697/


All Articles