oracle與mysql除重刪除

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);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章