I need to select one randomly selected row from each cat. I created sample MySql query with data as below;
select 1 id, 1 cat from dual
union all select 2 id, 1 cat from dual
union all select 3 id, 1 cat from dual
union all select 4 id, 2 cat from dual
union all select 4 id, 2 cat from dual
union all select 4 id, 3 cat from dual;
I need to return one randomly selected row from cat 1, another row from cat 2 and so on.
I can use rand() function to create random field, but how to use group or other method to get desired result? Other similar posts here did not solved what I'm looking for..
I have to avoid stored procedures, functions or heavy queries, because I have big data to handle. Any idea would be highly appreciated.
Aucun commentaire:
Enregistrer un commentaire