I'm having trouble creating a query that will select the newest record in a related record. I have a table of items that have related records in the table "StockTake". StockTake contains 3 fields:
ItemID
StockTakeDate
Quantity
Basically, I want to select the record in StockTake that has the most recent StockTakeDate for each Item. The below query does this, but I also want this query to select all items that have NO records in StockTake.
This is what I have so far:
SELECT Items.*, StockTake.StockTakeDate, StockTake.Quantity
FROM Items LEFT JOIN StockTake ON Items.ItemID = StockTake.ItemID
WHERE (StockTake.StockTakeDate)=(SELECT
MAX(StockTake.StockTakeDate)
FROM
StockTake
WHERE
Items.ItemID = StockTake.ItemID)
How can I make this also select items with no records in StockTake?
Thanks!
ItemID
StockTakeDate
Quantity
Basically, I want to select the record in StockTake that has the most recent StockTakeDate for each Item. The below query does this, but I also want this query to select all items that have NO records in StockTake.
This is what I have so far:
SELECT Items.*, StockTake.StockTakeDate, StockTake.Quantity
FROM Items LEFT JOIN StockTake ON Items.ItemID = StockTake.ItemID
WHERE (StockTake.StockTakeDate)=(SELECT
MAX(StockTake.StockTakeDate)
FROM
StockTake
WHERE
Items.ItemID = StockTake.ItemID)
How can I make this also select items with no records in StockTake?
Thanks!