J
Jon Lewis
Hi All
The above subject continues to baffle me!
http://www.mvps.org/access/queries/qry0020.htm
This link was posted a few messages ago but IMO these methods don't work
when there are duplicate combinations of the GroupBy and Totalled Fields in
the data source.
Consider the following:
TaskID ContactID Due Type
1 1 01/04/2007 Call
2 1 01/04/2007 Write
3 1 01/05/2007 Email
4 2 01/04/2007 Call
5 2 01/05/2007 Write
6 2 01/05/2007 Email
7 3 01/06/2007 Fax
8 4 01/05/2007 Call
9 5 01/07/2007 Email
10 5 01/07/2007 Call
11 5 01/07/2007 Call
Each task (PK) relates to a contact (FK) and has a due date and type
How do I get the earliest due date of a task for each contact and a related
field (Type or TaskID). When there are duplicate ContactID & Due
combinations then the first record should be returned (the lowest TaskID
would make sense).
SELECT tblTasks.ContactID, Min(tblTasks.Due) AS MinOfDue,
First(tblTasks.TaskID) AS FirstOfTaskID
FROM tblTasks
GROUP BY tblTasks.ContactID;
appears to work (returns 5 records) but I know from experience that
FirstOfTaskID could return a TaskID from a different record. Whilst it
works with the above data, it does not work with the table from which this
data is sampled although I can't figure out why.
The methods in the above link don't work .
e.g
SELECT Q.ContactID, Q.TaskID
FROM tblTasks AS Q INNER JOIN (SELECT ContactID, Min(Due) As S
FROM tblTasks
GROUP BY ContactID) AS T ON (Q.Due=T.S) AND (Q.ContactId=T.ContactId);
returns 8 rows of ContactID and TaskID
I'd like a query (or nest of queries) to return 5 records (TaskID's 1, 4,
7,8,9) - can anyone help please?
TIA
The above subject continues to baffle me!
http://www.mvps.org/access/queries/qry0020.htm
This link was posted a few messages ago but IMO these methods don't work
when there are duplicate combinations of the GroupBy and Totalled Fields in
the data source.
Consider the following:
TaskID ContactID Due Type
1 1 01/04/2007 Call
2 1 01/04/2007 Write
3 1 01/05/2007 Email
4 2 01/04/2007 Call
5 2 01/05/2007 Write
6 2 01/05/2007 Email
7 3 01/06/2007 Fax
8 4 01/05/2007 Call
9 5 01/07/2007 Email
10 5 01/07/2007 Call
11 5 01/07/2007 Call
Each task (PK) relates to a contact (FK) and has a due date and type
How do I get the earliest due date of a task for each contact and a related
field (Type or TaskID). When there are duplicate ContactID & Due
combinations then the first record should be returned (the lowest TaskID
would make sense).
SELECT tblTasks.ContactID, Min(tblTasks.Due) AS MinOfDue,
First(tblTasks.TaskID) AS FirstOfTaskID
FROM tblTasks
GROUP BY tblTasks.ContactID;
appears to work (returns 5 records) but I know from experience that
FirstOfTaskID could return a TaskID from a different record. Whilst it
works with the above data, it does not work with the table from which this
data is sampled although I can't figure out why.
The methods in the above link don't work .
e.g
SELECT Q.ContactID, Q.TaskID
FROM tblTasks AS Q INNER JOIN (SELECT ContactID, Min(Due) As S
FROM tblTasks
GROUP BY ContactID) AS T ON (Q.Due=T.S) AND (Q.ContactId=T.ContactId);
returns 8 rows of ContactID and TaskID
I'd like a query (or nest of queries) to return 5 records (TaskID's 1, 4,
7,8,9) - can anyone help please?
TIA