This bit of code should populate the playlist with five songs that have appeared in the requests table, randomly, and obey the settings for the track/artist repeat rules:
SELECT songs.ID, songs.artist, songs.title FROM songs
LEFT JOIN requests ON songs.ID= requests.songID
LEFT JOIN queuelist ON songs.ID = queuelist.songID OR songs.artist = queuelist.artist
WHERE songs.enabled=1
AND ((start_date <= Now()) AND (end_date >= NOW() OR `end_date` = '2002-01-01 00:00:01'))
AND (TIMESTAMPDIFF(MINUTE, date_played, NOW())>$TrackRepeatInterval$ AND TIMESTAMPDIFF(MINUTE, artist_played, NOW())>$ArtistRepeatInterval$)
AND (queuelist.songID IS NULL OR queuelist.artist IS NULL)
AND songs.ID= requests.songID
AND songs.song_type=0
ORDER BY RAND() DESC LIMIT 5;
One thought on “Tracks Rotation SQL Query: Load five songs from the requests table”