首 页  资讯中心 下载中心 资讯教程 最新下载 发布软件 发布文章 网通站 电信站繁體中文
设为首页
加入收藏
联系我们
 
您当前的位置:曾子源码软件下载站 -> 数据库 -> MS SQL -> 文章内容 退出登录 用户管理
热门文章
· 常用C,VC,C++书籍下..
· 新概念英语视频教程..
· 常用 JAVA JAVA2 J..
· 《梦幻麻将馆9雀圣争..
· 新东方英语视频教程..
· 常用VB,Visual Basi..
· [组图] After Effect..
· WINDOWS 所有系统文..
· [组图] 让机器运行多..
· 全美经典学习指导系..
相关文章
· 诡计多端 黑客攻破S..
· [图文] 三种方法查看..
· 超实用 五种方法快速..
· ASPX保存远程图片到..
· [组图] 小技巧 多种方..
· 用ASP实现网页保密的..
· [组图] 让烦恼不在 修..
· [组图] 节约成本 详解..
· 防止ACCESS数据库被..
· 黑客破解Email账号常..
在SQL中删除重复记录(多种方法)
作者:无从考证  来源:中国软件  发布时间:2005-12-29 23:06:42  发布人:我爱源码

减小字体 增大字体

2. 删除的几种方法:

 

1)通过建立临时表来实现

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

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

SQL> insert into employee select * from temp_emp;  (再将临时表里的内容插回来)

 

( 2)通过唯一rowid实现删除重复记录.Oracle中,每一条记录都有一个rowidrowid在整个数据库中是唯一的,rowid确定了每条记录是在Oracle中的哪一个数据文件、块、行上。在重复的记录中,可能所有列的内容都相同,但rowid不会相同,所以只要确定出重复记录中那些具有最大或最小rowid的就可以了,其余全部删除。

SQL>delete from employee e2 where rowid not in (
       
select max(e1.rowid) from employee e1 where

        e1.emp_id=e2.emp_id and e1.emp_name=e2.emp_name and e1.salary=e2.salary);--这里用min(rowid)也可以。

 

SQL>delete from employee e2 where rowid <(
       
select max(e1.rowid) from employee e1 where
        e1.emp_id
=e2.emp_id and e1.emp_name=e2.emp_name and

                  e1.salary=e2.salary);

 

3)也是通过rowid,但效率更高。

SQL>delete from employee where rowid not in (
       
select max(t1.rowid) from employee t1 group by

         t1.emp_id,t1.emp_name,t1.salary);--这里用min(rowid)也可以。

 

    EMP_ID EMP_NAME                                     SALARY

---------- ---------------------------------------- ----------

         1 sunshine                                      10000

         3 xyz                                             30000

         2 semon                                         20000


上一页  [1] [2] 

[] [返回上一页] [打 印] [收 藏]
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [发表评论...]
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 网站信息排名查询
Copyright © 2004-2006 Zasp.Net. All Rights Reserved .