silverkid
silverkid

Reputation: 9573

mysql query with random and desc

this is a mysql table

num        wt
a          24
e          22
c          11
d          24
b          13
f          12

how can i create a mysql query which will display with descending order of weights and give random sorting to num with same weight . thus the select query can have two valid results

a    24
d    24
e    22 
b    13
f    12
c    11 

AND

d    24
a    24
e    22 
b    13
f    12
c    11 

Upvotes: 0

Views: 3800

Answers (1)

Adriaan Stander
Adriaan Stander

Reputation: 166396

Try using

SELECT *
FROM YourTable
ORDER BY wt DESC, RAND()

Upvotes: 3

Related Questions