G
Guest
I have a query to select the MAX of the inspectionID by StructureID from the
inspectionhistory table. But if there is more than 1 record per structureID
and there not identical, I get both of the records instead of the
inspectionID MAX.
EX:
InspectionID Date Inspected Issued StructureID
1 1/1/1999 (checkbox) (checkbox) 0001
2 10/6/1999 (checkbox) (checkbox) 0001
Here is the SQL:
SELECT Max(InspectionHistory.InspectionID) AS InspectionID,
InspectionHistory.Date, InspectionHistory.Inspected,
InspectionHistory.Issued, MainUnitData.StructureID
FROM (MainAreaData INNER JOIN (InspectionFrequency INNER JOIN MainUnitData
ON InspectionFrequency.InspectionFrequencyID =
MainUnitData.InspectionFrequencyID) ON MainAreaData.UnitID =
MainUnitData.UnitID) INNER JOIN InspectionHistory ON MainUnitData.StructureID
= InspectionHistory.StructureID
GROU BY InspectionHistory.Date, InspectionHistory.Inspected,
InspectionHistory.Issued, MainUnitData.StructureID
HAVING (((InspectionHistory.Date) Between CDate([Forms]![IDRForm].[SDate])
And CDate([Forms]![IDRForm].[EDate])));
Thanks!
inspectionhistory table. But if there is more than 1 record per structureID
and there not identical, I get both of the records instead of the
inspectionID MAX.
EX:
InspectionID Date Inspected Issued StructureID
1 1/1/1999 (checkbox) (checkbox) 0001
2 10/6/1999 (checkbox) (checkbox) 0001
Here is the SQL:
SELECT Max(InspectionHistory.InspectionID) AS InspectionID,
InspectionHistory.Date, InspectionHistory.Inspected,
InspectionHistory.Issued, MainUnitData.StructureID
FROM (MainAreaData INNER JOIN (InspectionFrequency INNER JOIN MainUnitData
ON InspectionFrequency.InspectionFrequencyID =
MainUnitData.InspectionFrequencyID) ON MainAreaData.UnitID =
MainUnitData.UnitID) INNER JOIN InspectionHistory ON MainUnitData.StructureID
= InspectionHistory.StructureID
GROU BY InspectionHistory.Date, InspectionHistory.Inspected,
InspectionHistory.Issued, MainUnitData.StructureID
HAVING (((InspectionHistory.Date) Between CDate([Forms]![IDRForm].[SDate])
And CDate([Forms]![IDRForm].[EDate])));
Thanks!