select *  from ITEMDETAIL where BRANCH+Code
in (select  BRANCH+Code from ITEMDETAIL
group by  BRANCH+Code
having count( BRANCH+Code)>1)
order by  BRANCH+Code



delete from ITEMDETAIL where RecordKey in
(select max(RecordKey)  from ITEMDETAIL where  BRANCH+Code
in (select   BRANCH+Code from ITEMDETAIL
group by  BRANCH+Code
having count( BRANCH+Code)>1)
group by  BRANCH+Code
)

