Query to Randomly Select X entries based on group (1 Viewer)

ellejay123

New member
Local time
Yesterday, 22:06
Joined
Mar 9, 2017
Messages
2
I have a table with employee names and order numbers they are responsible for. I want to be able to randomly select 2 orders for each employee.

For example I have a list of 10 orders assigned to 4 employees:

Employee | Order #
Adam | 1
Adam | 2
Adam | 3
Betty | 4
Betty | 5
Betty | 6
Betty | 7
Carl | 8
Carl | 9
Dave | 10


And I want to return something like the following results:
Employee | Order #
Adam | 1
Adam | 3
Betty | 4
Betty | 5
Carl | 8
Carl | 9
Dave | 10

Everything I've found so far has been just returning 5 random entries, or 10 random entries. But I haven't found anything that allows for the grouping on another field such as Employee.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 03:06
Joined
Feb 19, 2013
Messages
16,607
base what you have found on a filtered recordset
 

ellejay123

New member
Local time
Yesterday, 22:06
Joined
Mar 9, 2017
Messages
2
Thanks CJ - Would you be able to elaborate on that a bit more?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 03:06
Joined
Feb 19, 2013
Messages
16,607
without knowing what you have found, not really possible.

Best I can suggest is you would use vba to take the id of the employee and use your random function based on a query which filters the table based on the id
 

Users who are viewing this thread

Top Bottom