`
xitong
  • 浏览: 6206562 次
文章分类
社区版块
存档分类
最新评论

在SQL中删除重复记录

 
阅读更多

1.查询重复的记录
select * from employee group by emp_id having count (*)>1;

2.
删除重复的记录
1 )通过建立临时表来实现

SQL>create table temp_emp as (select distinct * from employee)

SQL> truncate table employee; (清空employee表的数据)

SQL> insert into employee select distinct * from temp_emp; (再将临时表里的内容插回来)
(2)通过rowid
SQL>delete from employee where rowid not in (select max(t1.rowid) from employee t1 group by
t1.emp_id
);


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics