I have the following query. The idea is to inner join the records and group them in order to get one record (the latest one) from each group.
- If I add the
GROUP BY
(like on the example bellow) it doesn't work. - If I remove the
GROUP BY
the query works but display duplicated data. - If I group by all fields that I selected before the inner join, it works but not as intended. It will display all records.
Any suggestions?
SELECT
Calibrations.Cert_No,
Calibrations.Cust_Ref,
Calibrations.Rec_Date,
Instruments.Inst_ID,
Instruments.Description,
Instruments.Model_no,
Instruments.Manufacturer,
Instruments.Serial_no,
Instruments.Status,
Instruments.Cust_Acc_No
FROM
Instruments
INNER JOIN
Calibrations ON Instruments.Inst_ID = Calibrations.Inst_ID
WHERE
Instruments.Cust_Name = '" & Session("MM_Username") & "'
AND Instruments.Cust_Acc_No = '" & Session("MM_Password") & "'
AND Instruments.Cust_Acc_No = '" & Replace(rsDue__MMColParam, "'", "''") & "'
AND Instruments.Status IN ('N')
GROUP BY
Instruments.Inst_ID
ORDER BY
Calibrations.Rec_Date DESC