samedi 14 février 2015

How to select a random row with a group by clause?

I have the following table


SQLFiddle


What I'm attempting to do is to select three random images but to make sure that no two images have the same object, what I attempted to do is to do a GROUP BY along with an ORDER BY rand() but that is failing as it is always giving me cat1.jpg, dog1.jpg, box1.jpg (All images whose path ends with 1 and not the others)


The fiddle includes the query I ran and how is it not working, any help will be much appreciated.


Aucun commentaire:

Enregistrer un commentaire