SELECT A.ID, A.tblCar, A.tblDrop
FROM tblContacts AS A INNER JOIN (
SELECT tblCar, Max(ID) AS LastID FROM tblContacts GROUP BY tblCar
) AS B ON A.ID = B.LastID AND A.tblCar = B.tblCar;
Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
SELECT A.ID, A.tblCar, A.tblDrop
FROM tblContacts AS A INNER JOIN (
SELECT tblCar, Max(ID) AS LastID FROM tblContacts GROUP BY tblCar
) AS B ON A.ID = B.LastID AND A.tblCar = B.tblCar
Many Thanks
I need the query to produce results depending on status of field in another table eg
tblContacts tblDrivers
ID tblCar tblDrop ID Car Finish Time
What is the difference between the 2 Returns ?
Don't pick the Car 99 because its Finish Time is not null in tblDrivers ?
SELECT A.ID, A.tblCar, A.tblDrop
FROM (tblContacts AS A INNER JOIN (
SELECT tblCar, Max(ID) AS LastID FROM tblContacts GROUP BY tblCar
) AS B ON A.ID = B.LastID AND A.tblCar = B.tblCar)
INNER JOIN tblDrivers AS D ON A.tblCar = D.Car
WHERE D.[Finish Time] Is Null;
Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
When I select the following query as the Recordsource on my Form it works first time ............
____________________________________________
SELECT A.ID, A.tblCar, A.tblDrop
FROM (tblContacts AS A INNER JOIN (
SELECT tblCar, Max(ID) AS LastID FROM tblContacts GROUP BY tblCar
) AS B ON A.ID = B.LastID AND A.tblCar = B.tblCar)
INNER JOIN tblDrivers AS D ON A.tblCar = D.Car
WHERE D.[Finish Time] Is Null;
_____________________________________________
I then get the following Error
"The Microsoft Jet Database Engine cannot find the input Table or Query ' Select tblCar, Max(ID)AS LastID FROM tblContacts GROUP BY tblCar' Make sure it exists and its name is spelled correctly." and the Query has altered to
SELECT A.ID, A.tblCar, A.tblDrop
FROM (tblContacts AS A INNER JOIN [SELECT tblCar, Max(ID) AS LastID FROM tblContacts GROUP BY tblCar]. AS B ON (A.tblCar = B.tblCar) AND (A.ID = B.LastID)) INNER JOIN tblDrivers AS D ON A.tblCar = D.Car
WHERE D.[Finish Time] Is Null;
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.