SELECT * FROM (SELECT A.*, RANK() OVER(PARTITION BY A.DR_ATP_ID, A.AT_CODE ORDER BY A.KEY_CODE) RANK FROM DR_ATP_DTL A) A WHERE RANK = 1