I have query to find the last transaction for the purchase of an item. The date is stored in a purchases header table and the item and the date are stored in a detail table. (This allowed the date to not have to be re-keyed on each item.) The query using MAX on the date field returns the last transaction just fine. But when I also add the cost field to the query, it returns other dates.
How can I get the cost to pull only from the transactions limited to the MAX criteria on the date field?
SQL code is:
SELECT PurchasesInvoiceDetail.ItemID, Max(PurchasesInvoice.TranDate) AS MaxOfTranDate, PurchasesInvoiceDetail.Cost
FROM PurchasesInvoice INNER JOIN PurchasesInvoiceDetail ON PurchasesInvoice.Reference = PurchasesInvoiceDetail.Reference
GROUP BY PurchasesInvoiceDetail.ItemID, PurchasesInvoiceDetail.Cost;
Thanks for the help
How can I get the cost to pull only from the transactions limited to the MAX criteria on the date field?
SQL code is:
SELECT PurchasesInvoiceDetail.ItemID, Max(PurchasesInvoice.TranDate) AS MaxOfTranDate, PurchasesInvoiceDetail.Cost
FROM PurchasesInvoice INNER JOIN PurchasesInvoiceDetail ON PurchasesInvoice.Reference = PurchasesInvoiceDetail.Reference
GROUP BY PurchasesInvoiceDetail.ItemID, PurchasesInvoiceDetail.Cost;
Thanks for the help