Query for Random Sample with Multiple Criteria

Hudas

Registered User.
Local time
Today, 07:09
Joined
May 13, 2013
Messages
55
Hi Everyone,

I am hoping someone could help me with my problem because I'm completely stuck. I've search the web but I can't find the answer. So here it goes...

I have table with [EmployeeName] and [DateReceived] column what I am hoping to accomplish is to get 5 samples of each Employee for each Date received.

I would greatly appreciate any help.

Thank you
Hudas
 
You'll need something like this pseudo code to get you started - Note that you need a unique ID in your data to make it work.

Code:
SELECT * 
FROM myTable 
WHERE ID in (SELECT Top 5 ID from myTable as tmp WHERE EmployeeName=myTable.EmployeeName and DateReceived=myTable.DateReceived)
 
Thank you very much... CJ_London

I've tried your query and its getting the top 5 Employee name for each date. I'm hoping that for each employee I will have 5 samples for each date
 
That code should produce 5 records for each employee so suggests there is something else.

please post some sample data from your table plus the query as you have written it
 
Here is the code in the SQL view of the query.

Code:
SELECT *
FROM tbl_Sent_Email
WHERE (((tbl_Sent_Email.ID) In (SELECT Top 5 ID from tbl_Sent_Email as tmp WHERE tbl_Sent_Email.UseriD and ReceivedDate=tbl_Sent_Email.ReceivedDate)));

ID is an Autonumber column
UserdiD is name of the Employees
ReceivedDate is a Date

I've attached sample data from the table
 

Attachments

you've missed a bit of the subquery out

.... WHERE tbl_Sent_Email.UseriD ....

should be

.... WHERE UserID=tbl_Sent_Email.UseriD ....
 

Users who are viewing this thread

Back
Top Bottom