Hi
I have a query that I am trying to get the information from product analysis table based on Max date.
I have 2 tables, Stocktranascations and Product.
I run the query below it brings back one row result giving max date, Product Code and Description. That is good.
However I need to show the StockActual field for that transaction which I held in stocktrasaction table, but when I add the file into the query it gives me 4 result rows and not just the one for the MAX Date and not just the one I expected.
I have tried different joins bt keep getting 4 rows instead of just the one with the MAX date. Could someone plese advise what I am doing wrong please and how to get the expected result, Thanks
I have a query that I am trying to get the information from product analysis table based on Max date.
I have 2 tables, Stocktranascations and Product.
I run the query below it brings back one row result giving max date, Product Code and Description. That is good.
SQL:
SELECT DISTINCT MAX(dbo.StockTransaction.StockTransactionDate) AS [Max Date], dbo.Product.ProductCode, dbo.Product.Description
FROM dbo.StockTransaction FULL OUTER JOIN
dbo.Product ON dbo.StockTransaction.ProductID = dbo.Product.ProductID
WHERE (dbo.StockTransaction.StockTransactionType = 32) AND (dbo.Product.ProductID = 32012)
GROUP BY dbo.Product.ProductCode, dbo.Product.Description
However I need to show the StockActual field for that transaction which I held in stocktrasaction table, but when I add the file into the query it gives me 4 result rows and not just the one for the MAX Date and not just the one I expected.
I have tried different joins bt keep getting 4 rows instead of just the one with the MAX date. Could someone plese advise what I am doing wrong please and how to get the expected result, Thanks
SQL:
SELECT DISTINCT MAX(dbo.StockTransaction.StockTransactionDate) AS [Max Date], dbo.Product.ProductCode, dbo.Product.Description, dbo.StockTransaction.StockActual
FROM dbo.StockTransaction FULL OUTER JOIN
dbo.Product ON dbo.StockTransaction.ProductID = dbo.Product.ProductID
WHERE (dbo.StockTransaction.StockTransactionType = 32) AND (dbo.Product.ProductID = 32012)
GROUP BY dbo.Product.ProductCode, dbo.Product.Description, dbo.StockTransaction.StockActual