oracle 數據庫中查詢重複數據:
select * from employee group by emp_name having count (*)>1;
查詢可以刪除的重複數據
select t1.* from employee t1 where (t1.emp_name) in (SELECT t2.emp_name from employee t2 group by emp_name having count (*)>1)
and t1.emp_id not in (select min(t3.emp_id) from employee t3 group by emp_name having count (*)>1);
刪除重複數據
delete from employee t1 where (t1.emp_name) in (SELECT t2.emp_name from employee t2 group by emp_name having count (*)>1)
and t1.emp_id not in (select min(t3.emp_id) from employee t3 group by emp_name having count (*)>1);
mysql數據庫中查詢重複數據
select * from employee group by emp_name having count (*)>1;
查詢可以刪除的重複數據
select t1.* from employee t1 where (t1.emp_name) in (select t4.emp_name from (select t2.emp_name from employee t2 group by t2.emp_name having count(*)>1) t4) and t1.emp_id not in (select t5.emp_id from (select min(t3.emp_id)
as emp_id from employee t3 group by t3.emp_name having count(*)>1) t5);
刪除重複的數據
delete t1 from employee t1 where (t1.emp_name) in (select t4.emp_name from (select t2.emp_name from employee t2 group by t2.emp_name having count(*)>1) t4)
and t1.emp_id not in (select t5.emp_id from (select min(t3.emp_id) as emp_id from employee t3 group by t3.emp_name having count(*)>1) t5);