A
A
Alexey2015-11-06 20:29:06
MySQL
Alexey, 2015-11-06 20:29:06

How to randomly sort records based on the first sort?

I select records from the database, I need to sort them so that the records are sorted by date, and if the date is the same, then by chance. Something like this:
SELECT * FROM `news` ORDER BY `date`, rand()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wol_fi, 2015-11-06
@dzheka3d

I can't vouch for the speed of execution, but something like this

select *, rand() as orderField  from news order by `date`, orderField

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question