I’m using a simple MySQL statement to query my DB for product suggestions sorted by clicks:
SELECT * FROM suggestions WHERE source = :source_item_id ORDER BY clicks DESC LIMIT 7
It all works as expected. However, if the clicks are the same, is there a way to tell MySQL to spit them out randomly?
Example:
Product Clicks
1 2
2 2
3 3
If queried, the order is 3, 2, 1 and it will always be this order if clicks don’t change. How can I randomize product 1 and 2 that have w clicks each? Every now and then I want to swap the result, i.e. make it 3, 1, 2 and maybe next time 3, 2, 1.
How about adding a column with a random value and having a secondary sort on it?