- 论坛徽章:
- 0
|
!!如何用一条SQL实现:如果几条记录一样,只保留一条
SQL>; create table a (
2 bm char(4), --编码
3 mc varchar2(20) --名称
4 )
5 /
表已建立.
SQL>; insert into a values('1111','1111');
SQL>; insert into a values('1112','1111');
SQL>; insert into a values('1113','1111');
SQL>; insert into a values('1114','1111');
SQL>; insert into a select * from a;
插入4个记录.
SQL>; commit;
SQL>; select rowid,bm,mc from a;
ROWID BM MC
------------------ ---- -------
000000D5.0000.0002 1111 1111
000000D5.0001.0002 1112 1111
000000D5.0002.0002 1113 1111
000000D5.0003.0002 1114 1111
000000D5.0004.0002 1111 1111
000000D5.0005.0002 1112 1111
000000D5.0006.0002 1113 1111
000000D5.0007.0002 1114 1111
查询到8记录.
查出重复记录
SQL>; select rowid,bm,mc from a where a.rowid!=(select max(rowid) from a b where a.bm=b.bm and a.mc=b.mc);
ROWID BM MC
------------------ ---- --------------------
000000D5.0000.0002 1111 1111
000000D5.0001.0002 1112 1111
000000D5.0002.0002 1113 1111
000000D5.0003.0002 1114 1111
删除重复记录
SQL>; delete from a a where a.rowid!=(select max(rowid) from a b where a.bm=b.bm and a.mc=b.mc);
删除4个记录.
SQL>; select rowid,bm,mc from a;
ROWID BM MC
------------------ ---- --------------------
000000D5.0004.0002 1111 1111
000000D5.0005.0002 1112 1111
000000D5.0006.0002 1113 1111
000000D5.0007.0002 1114 1111 |
|