I solved it. In the end I used two queries;
The first pulls out the names and daterange (date + time)
The second runs on the first and pulls out the Max daterange for each person.
I think the problem was still in the ID relationship. Thanks for all your help Golom.
The extra records are not identical unfortunately, which is why I believe the problem lies in the MAX() aggregrate function.
It SHOULD be working, I just don't know why it isn't.
Here's some more sample data that your SQL returns:
Assigned To Date_of_Update Time_of_Update
David Yiu 8/22/2006...
Thanks for the replay again Golom, I've been on holidays the past week which is why I haven't replied.
Using this SQL seems to get me almost accurate results, save that it returns more than one record for each person (Assigned To). This would seem to me that it is not correctly selecting the...
Sample data:
Data_Tasks
ID Assigned To
124 Bob
125 Bob
126 Bob
127 Jim
128 Sally
129 Sally
130 Jim
131 Sally
132 Bob
133 Jim
134 Jones
135 Jones
136 Jones...
[Assigned To] is actually in a different table, "Data_Tasks" and I wasn't able to modify your SQL to incorporate that. Thanks for your efforts though!
The two tables can be joined by Data_Tasks.ID and Data_Task_Update_History.task_ID
Thanks Golom, that works as I worded it. Unfortunately for me, I worded my problem badly :) How do I separate this out for each person?
In Data_Tasks I have an "Assigned To" field, and I need to get this max date/time for each person.
Hi guys,
I'm using Last to pull the latest date and time (separate fields) in a Many table, linked to a One table.
1: Data_Tasks
Many: Data_Task_Update_History
What I'm finding is that it is finding the date/time of the last record ID in Data_Task_Update_History, rather than the Last Date...
Sorry to bother again, however this doesn't seem to pull out tasks that have no update. I think the logic behind that is because it is looking for ID's "in" a query result, when a task has no updates it's ID won't be there to be found. Is there any way around this?
Ah, nevermind. I found the problem. I forgot to rename the SELECT TOP 2 ID to SELECT TOP 2 history_ID. It all works now. Thanks mp9.
SELECT Data_Tasks.*, Data_Task_Update_History.*
FROM Data_Tasks LEFT JOIN Data_Task_Update_History ON Data_Tasks.ID = Data_Task_Update_History.task_ID
WHERE...
Thanks for the reply mp9. The table structure is as follows:
Data_Tasks
ID
....
Data_Task_Update_History
history_ID
task_ID
date_of_update
...
---------------------------------------
When I changed your code to reflect my table structure I get no results. When I changed it again to this...
Hi guys,
I have a 1-M relationship where 1 Task will have Many updates. In a query I need to get all Tasks within a criteria, but only the Top 2 updates. I also need to be able to show Tasks even if they have no updates. I think this is possible using the TOP predicate and subqueries, but for...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.