SELECT aircrafts1.ac_reg, Last(PFR_failure_entry.PH) AS LastOfPH, if(([ATA] Like '7%' Or [ATA] Like '27%'),"SAFETY",if(([ATA] Like '24%' Or [ATA] Like '21%'),"CRITICAL","GENERAL")) AS System, PFR_failure_entry.message, PFR_failure_entry.message, PFR_failure_entry.PH
FROM aircrafts1 INNER JOIN (PFR_AC_FLT_detail INNER JOIN PFR_failure_entry ON PFR_AC_FLT_detail.PFR_fail_id = PFR_failure_entry.PFR_fail_id) ON aircrafts1.ac_id = PFR_failure_entry.ac_id
WHERE (((PFR_AC_FLT_detail.DATE) Between Now()-3 And Now()))
GROUP BY aircrafts1.ac_reg, PFR_failure_entry.ATA, PFR_failure_entry.message, PFR_failure_entry.message, PFR_failure_entry.PH
HAVING (((Last(PFR_failure_entry.PH))='03' Or (Last(PFR_failure_entry.PH))='04' Or (Last(PFR_failure_entry.PH))='05' Or (Last(PFR_failure_entry.PH))='06' Or (Last(PFR_failure_entry.PH))='07' Or (Last(PFR_failure_entry.PH))='08'));