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  
  •  Dropdowns in grid view 'edit item template' not working
  •  How do you import outlook express 6 messages into Windows Live Mail and have them in the proper folders?
  •  Cannot use remote executables after I upgraded to R2
  •  Mixed tooltips using AddTool (GetDlgItem (IDC_THIS), IDC_THIS) and AddTool (this, LPSTR_TEXTCALLBACK) how to.
  •  VPN client (Check point Secure client) not able to browse to any website on the machine once connected to the VPN.
  •  How do I remove special characters in a query?
  •  Purge Deleted items from database immediatly after message recall
  •  Expert Notify Thread - For Experts only (those answering questions in the MS Access Zone).
  •  DNS root hints not working Windows 2008
  •  can i use right([ClientName] to get the last part of a string in a Microsoft Access query if i don't know how long the last part is?
  •  
    programming4us programming4us