If the title of my question was confused, I explain: I want to sort a result of a given query from MYSQL
.
Example:
SELECT * FROM
usuarios
ORDER BY
cidade = 'BH' DESC,
cargo = 'Programador' DESC
But I would like that if more than one user falls into the same ordering order (for example, the user has the same city and the same position in that order), the ordering is random.
Example:
| nome | cargo | cidade |
-----------------------------------------
| wallace | programador | bh |
| helbert | programador | bh |
| simão | programador | sp |
| miguel | venda | sp |
In the above example, wallace and helbert match the ordering of cargo
and cidade
simultaneously.
However, regardless of the criteria that MYSQL
will use after this sort order, I wanted the result to be random between those two (when they are identical).
In other words, if the results of ORDER BY
result in the same amount of items that match the ordering, I want the next ordering between them to be random (one hour wallace will be first, another time may be helbert ).
How do I do this in MYSQL
?