jeudi 14 mars 2019

Select random rows but without duplicates of values from another column

I have the following query which gives me 3 random names,ids and top_tags:

SELECT  Name
     , id
     , top_tag 
  FROM artists 
 WHERE  not find_in_set (id,'1,2,3,4') 
 order 
    by rand() 
 limit 3

It works fine, however, I do need another condition. I have a column name top_tag (int), I need that the result will include 3 unique top_tag values and not duplicates of top_tag.




Aucun commentaire:

Enregistrer un commentaire