Skip to main content
1 of 3
jyao
  • 3.1k
  • 1
  • 13
  • 27

I think the following query is more intuitive to understand

select max(Report_Result) as ReportResult, PARAMETER_NAME, GW_LOCATION_ID,
t.DETECT_FLAG -- all other columns can be listed here 
from SLVs_Flagged s
cross apply (  
SELECT * 
FROM SLVs_Flagged
where PARAMETER_NAME = s.PARAMETER_NAME 
and GW_LOCATION_ID = s.GW_LOCATION_ID 
and Report_Result = s.ReportResult 
) T
group by PARAMETER_NAME, GW_LOCATION_ID
jyao
  • 3.1k
  • 1
  • 13
  • 27