ORDER BY RAND () in 2 columns

0

Well earlier I posted a problem about deleting 1 select that was solved but now I had another problem.

My idea is to create a playlist that prioritizes status 1. Whenever a user posts the video it is inserted with status 1. After the video is played I update it by changing it to 0 status. The playlist will continue playing videos that have status 0

The problem is that when all videos are with status = 0 the playlist will always be catching the same video in case the select below will always get id 7, I am trying to randomize without success.

SELECT * FROM playlist ORDER BY status DESC,id ASC, RAND() LIMIT 1
    
asked by anonymous 04.04.2018 / 02:24

1 answer

2

Using id ASC, RAND() means that it will sort first by id and if you have two rows with the same value it will use RAND() to sort. Only this will never happen because there will never be two equal primary keys ( id ) in the same table. To fix this remove the id ASC from the command

In addition, the use of the primary key as an ascending order as a second sorting option is deprecated, the data in the table is already naturally sorted by id , when doing any query, with or without ORDER BY , the id 1 will never be in front of the id 0 line, except for the effect of sorting another field (if it exists)

    
04.04.2018 / 03:12