jeudi 10 février 2022

MySQL RAND() from a range of latest entries (ORDER BY id DESC LIMIT 0,1) – Is this possible?

Here's what I'm trying to achieve:

I would like to show a random entry from the latest posts in four categories.

I've tried combining RAND() with ORDER BY contentID DESC LIMIT 0,1 but that doesn't work:

SELECT cc.pageID, cc.contentID, cc.contentTitle, cc.contentDate, cc.contentImage, cc.contentText, cs.pageName, cs.pageLabel_".$lang." AS pageLabel, cs.pageImage, ca.authorImage 
FROM cheeseus_content cc 
JOIN cheeseus_sections cs ON cc.pageID = cs.pageID 
JOIN cheeseus_authors ca ON cc.contentAuthor = ca.authorID 
WHERE cc.pageID IN (18, 19, 20, 21) 
ORDER BY RAND(), cc.contentID DESC LIMIT 0,1

Is what I'm looking for possible and how?




Aucun commentaire:

Enregistrer un commentaire