Hoping someone can help me out with this one. I am using Access 2010 and trying to create a query to show the last records for 12 unique foreign keys in a table.
I am tracking sealer inventory for 12 pumps in a shop. Each pump can be changed multiple times in a week. I need a query that will show the last sealer barrels on these 12 pumps. I thought that a Top N subquery would do the trick, but I am not getting the results I need:
The Inventory table records the sealer inventory changes. The Pump Table has the list of the 12 Sealer pumps in the shop.
Can anyone offer some advice on how I can get the desired results? Am I over thinking this? Thank you.
I am tracking sealer inventory for 12 pumps in a shop. Each pump can be changed multiple times in a week. I need a query that will show the last sealer barrels on these 12 pumps. I thought that a Top N subquery would do the trick, but I am not getting the results I need:
Code:
SELECT t.InventoryID, t.PumpID, t.SealerType, t.ExpiryDate, t.LotNo
FROM Inventory AS t
WHERE (((t.[PumpID]) In (SELECT TOP 12 PumpID
FROM Inventory
WHERE PumpID = t.PumpID
ORDER BY InventoryID DESC, PumpID)))
ORDER BY t.ExpiryDate, t.InventoryID DESC , t.PumpID;
The Inventory table records the sealer inventory changes. The Pump Table has the list of the 12 Sealer pumps in the shop.
Can anyone offer some advice on how I can get the desired results? Am I over thinking this? Thank you.