I have two tables which are related in the following way:
I am trying to create a query that returns all results from the Hardware table and the single most recent related records from the Loan table.
Here is what I've tried:
Now the above code returns all records from the Hardware table and all records from the Loans table. But again I need all records from Hardware and only the most recent related records from Loans (which is why I'm using Max date).
I really hope this makes sense - I'll be truely very grateful for anyone can help.
Many thanks
daniel
I am trying to create a query that returns all results from the Hardware table and the single most recent related records from the Loan table.
Here is what I've tried:
Code:
SELECT Hardware.hardwareOwner, Hardware.hardwareSerialNo, Hardware.hardwareID, Loan.loanTimeDate, Loan.loanUserID
FROM Hardware LEFT JOIN Loan ON Hardware.hardwareID = Loan.loanHardwareID
WHERE (((Hardware.hardwareOwner) Like 'TSPARE*' Or (Hardware.hardwareOwner) Like 'RSPARE*'))
AND (SELECT Max(Loan.loanTimeDate) AS MaxOfloanTimeDate FROM Loan;)
ORDER BY Hardware.hardwareOwner;
Now the above code returns all records from the Hardware table and all records from the Loans table. But again I need all records from Hardware and only the most recent related records from Loans (which is why I'm using Max date).
I really hope this makes sense - I'll be truely very grateful for anyone can help.
Many thanks
daniel