1. 程式人生 > >oracle查詢/去除重複值

oracle查詢/去除重複值

-- 查詢重複值及最小的id
select	min (id), province, city, count (*) cnt
	from t 
	group by province, city
	having count (*) > 1;

-- 保留最小的重複值
delete from t  
	where id not in (
		select min(id) from t
			group by province, city
);