Question : SQL limit rows in joined table

hey,

i have an Access sql query that join a few tables. However one particular table, i only want to return one row. See bellow

I only need the most recent Date field from the MatOut table. At the moment it is returning all the rows associated with the PartNo.

How do i limit it to only showing the most recent date field.


many thanx

nathan
Code Snippet:
1:
2:
3:
SELECT Parts.ShortID AS PART, Parts.Description AS DESCRIPTION, Sum(PartsActive.Units) AS UNITS, Parts.curCost AS [CURRENT COST], Sum(Parts.curCost*PartsActive.Units) AS TOTAL, PartsActive.[Date In] AS DateIn, MatOut.Date AS DateOut
FROM (Parts RIGHT JOIN ((PartsActive LEFT JOIN Vendor ON PartsActive.Associate = Vendor.Rec) LEFT JOIN tblCompanyInfo ON PartsActive.WID = tblCompanyInfo.Rec) ON Parts.PartNo = PartsActive.Part) LEFT JOIN MatOut ON PartsActive.Part = MatOut.PartNo
GROUP BY Parts.ShortID, Parts.Description, Parts.curCost, PartsActive.[Date In], Vendor.Name, PartsActive.Active, Parts.DC, MatOut.Date;

Answer : SQL limit rows in joined table

here we go, assuming that the PartNo field is a numeric field:
1:
2:
3:
4:
SELECT Parts.ShortID AS PART, Parts.Description AS DESCRIPTION, Sum(PartsActive.Units) AS UNITS, Parts.curCost AS [CURRENT COST], Sum(Parts.curCost*PartsActive.Units) AS TOTAL, PartsActive.[Date In] AS DateIn, MatOut.Date AS DateOut
FROM (Parts RIGHT JOIN ((PartsActive LEFT JOIN Vendor ON PartsActive.Associate = Vendor.Rec) LEFT JOIN tblCompanyInfo ON PartsActive.WID = tblCompanyInfo.Rec) ON Parts.PartNo = PartsActive.Part) 
LEFT JOIN MatOut ON ( PartsActive.Part = MatOut.PartNo AND MatOut.Date = DMAX("Date", "MatOut", "PartNo = " & PartsActive.Part ))
GROUP BY Parts.ShortID, Parts.Description, Parts.curCost, PartsActive.[Date In], Vendor.Name, PartsActive.Active, Parts.DC, MatOut.Date;
Random Solutions  
 
programming4us programming4us