```
select a.dda_pk
from direct_table a      
where a.dda_type = 'B'  
  and a.dda_status = 'D'        
  and a.dda_location = '01'      
group by a.dda_emp_idno       
having  dda_pk <  max(a.dda_pk) 
    and a.dda_status = 'D'  
    and a.dda_location = '01'

```

> 
> Column 'direct\_deposit\_audit.dda\_pk' is invalid in the HAVING clause
>  because it is not contained in either an aggregate function or the
>  GROUP BY clause.
> 
> 
>