Nrc
Nrc

Reputation: 9787

ORDER by score AND something else

I have a sql database with a column text and another for score. I want the user see the 5 best text. This is my first shot:

"SELECT score, text 
 FROM well 
 ORDER BY score DESC
 LIMIT 5;"

It works well. But, if there is several texts with the same score it always show the same. (by default by date). It would be useful for the user to see different text each time if the score is the same.

In a practical simplified case, if I have 6 text with a score of 10 I would like to show each time 5 different and in different order. Is it possible?

Upvotes: 0

Views: 39

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269693

You can randomize them:

order by score desc, rand()

However, that does not guarantee that you'll get a different ordering on the following run.

Upvotes: 3

Related Questions