---
title: "oracle 去重sql"
author: "qnzhl"
date: "2015-04-12T10:20:21Z"
tags: ["Oracle"]
categories: ["数据库"]
slug: "oracle-sql"
draft: false
lastmod: "2015-05-03T08:44:06Z"
id: 2201628
url: "https://qnzhl.iteye.com/blog/2201628"
---

三种：

1.delete from table1 a where rowid not in(
    select max(rowid) from table1 b group by (去重字段)); 


2.delete from table1 a where rowid !=(
select max(rowid) from table b where a.name=b.name and b.sex=a.sex );



3.insert into tem_tab select distinct mobile from old_tab;
  drop table old_tab;
  rename tem_tab to old_tab;


4.delete from table1 where rowid in(
select rowid from （
select rowid,deptno,name,age, row_number() over(partition by deptno order by age desc) rn from emp_zh）where rn>1);---分组去重