Gerbers404
Programmer
Hello all,
I've been searching this forum for awhile, and have found people with similar problems, but haven't been able to find any resolution to this. I have a query on a left-joined table, and I want to only return the recrods with most recent (max) Calibration Date from the right table(Calibration_Header). The 4 fields from
the right table I'm using in the query have different values in them for any given Gage_ID, so when I try to use the Max function on the date field, it still shows the other records with differences from the other 3 fields in the right table. Wow, did that make sense or what?
Anyway, here's the sql statement:
SELECT [Gage Master].GM_Type, [Gage Master].Gage_ID, [Gage Master].Status, [Gage Master].Gage_SN, [Gage Master].Asset_No, [Gage Master].Model_No, [Gage Master].Current_Location, [Gage Master].Calibration_Frequency, [Gage Master].Calibration_Frequency_UOM, [Gage Master].Notes, [Gage Master].Last_Calibration_Date, [Gage Master].Next_Due_Date, [Gage Master].Operating_Range, [Gage Master].Plus_Tolerance, [Gage Master].Minus_Tolerance, Calibration_Header.CertNo, Calibration_Header.Results, Calibration_Header.CalibType, Max(Calibration_Header.Calibration_Date) AS MaxOfCalibration_Date
FROM [Gage Master] LEFT JOIN Calibration_Header ON [Gage Master].Gage_ID = Calibration_Header.Gage_ID
GROUP BY [Gage Master].GM_Type, [Gage Master].Gage_ID, [Gage Master].Status, [Gage Master].Gage_SN, [Gage Master].Asset_No, [Gage Master].Model_No, [Gage Master].Current_Location, [Gage Master].Calibration_Frequency, [Gage Master].Calibration_Frequency_UOM, [Gage Master].Notes, [Gage Master].Last_Calibration_Date, [Gage Master].Next_Due_Date, [Gage Master].Operating_Range, [Gage Master].Plus_Tolerance, [Gage Master].Minus_Tolerance, Calibration_Header.CertNo, Calibration_Header.Results, Calibration_Header.CalibType, Calibration_Header.Calibration_Date
ORDER BY [Gage Master].Gage_ID, [Gage Master].Status;
I figure that if I didn't have to group by the other 3 fields from the Calibration_Header table, it would work fine, But have had no luck getting anything to work.
Any ideas and suggestions would be appreciated. Thank you!
Gerbers404
I've been searching this forum for awhile, and have found people with similar problems, but haven't been able to find any resolution to this. I have a query on a left-joined table, and I want to only return the recrods with most recent (max) Calibration Date from the right table(Calibration_Header). The 4 fields from
the right table I'm using in the query have different values in them for any given Gage_ID, so when I try to use the Max function on the date field, it still shows the other records with differences from the other 3 fields in the right table. Wow, did that make sense or what?
SELECT [Gage Master].GM_Type, [Gage Master].Gage_ID, [Gage Master].Status, [Gage Master].Gage_SN, [Gage Master].Asset_No, [Gage Master].Model_No, [Gage Master].Current_Location, [Gage Master].Calibration_Frequency, [Gage Master].Calibration_Frequency_UOM, [Gage Master].Notes, [Gage Master].Last_Calibration_Date, [Gage Master].Next_Due_Date, [Gage Master].Operating_Range, [Gage Master].Plus_Tolerance, [Gage Master].Minus_Tolerance, Calibration_Header.CertNo, Calibration_Header.Results, Calibration_Header.CalibType, Max(Calibration_Header.Calibration_Date) AS MaxOfCalibration_Date
FROM [Gage Master] LEFT JOIN Calibration_Header ON [Gage Master].Gage_ID = Calibration_Header.Gage_ID
GROUP BY [Gage Master].GM_Type, [Gage Master].Gage_ID, [Gage Master].Status, [Gage Master].Gage_SN, [Gage Master].Asset_No, [Gage Master].Model_No, [Gage Master].Current_Location, [Gage Master].Calibration_Frequency, [Gage Master].Calibration_Frequency_UOM, [Gage Master].Notes, [Gage Master].Last_Calibration_Date, [Gage Master].Next_Due_Date, [Gage Master].Operating_Range, [Gage Master].Plus_Tolerance, [Gage Master].Minus_Tolerance, Calibration_Header.CertNo, Calibration_Header.Results, Calibration_Header.CalibType, Calibration_Header.Calibration_Date
ORDER BY [Gage Master].Gage_ID, [Gage Master].Status;
I figure that if I didn't have to group by the other 3 fields from the Calibration_Header table, it would work fine, But have had no luck getting anything to work.
Any ideas and suggestions would be appreciated. Thank you!
Gerbers404