---
title: "oracle借助rowid选择或删除重复行"
author: "penggle"
date: "2011-07-12T14:28:41Z"
tags: []
categories: ["数据库"]
slug: "oracle-rowid"
draft: false
lastmod: "2011-07-12T14:28:41Z"
id: 1122434
url: "https://penggle.iteye.com/blog/1122434"
---

```sql

有表：
create table t_test1(
   id        number,
   name      varchar2(50),
   age       number,
   birthday  date
);
1、选择出重复的行
select a.* from t_test1 a
 where rowid <> (select max(rowid)
                   from t_test1 b
                  where a.id = b.id  -- where语句后面的条件是你定义重复的规则
                    and a.name = b.name
                    and a.age = b.age
                    and a.birthday = b.birthday);

2、删除重复的行
delete from t_test1 a
 where rowid <> (select max(rowid)
                   from t_test1 b
                  where a.id = b.id
                    and a.name = b.name
                    and a.age = b.age
                    and a.birthday = b.birthday);

```