Use GROUP BY and return more than 2 columns
You can use ROW_NUMBER:

with cte as 
(
    select  *,
            RN = ROW_NUMBER() OVER(PARTITION BY unid ORDER BY cdts2 DESC)
    from un_hi 
    where ag_id = 'bfd' 
    and cdts &gt; '201708' 
    and unit_status != 'uc'
)
select *
from cte
where RN = 1;