mercredi 1 juillet 2020

SQL Select n random groups and return all records

I can't seem to find a solution to this exact answer, without chaining together 2 or more queries together. A hypothetical dataset and query is as follows:

Say I want n = 3 random groups from the following data.

id, group, value
1,a,23
1,a,3
1,b,2
1,a,432
1,b,123
1,d,23
1,d,11
1,c,23
1,c,234
1,a,223
1,c,32

An example result of a query would be n=3 random groups (i.e. b,c,d):

id, group, value
1,b,2
1,b,123
1,d,23
1,d,11
1,c,23
1,c,234
1,c,32

How might this work?




Aucun commentaire:

Enregistrer un commentaire