목차
![[Oracle] Oracle 중복데이터 제거(feat. delete from table + group by having) [Oracle] Oracle 중복데이터 제거(feat. delete from table + group by having)](https://blog.kakaocdn.net/dn/oexwo/btrSlDyDCTw/6dk3eosP9ObqSEWNRHQpLK/img.png)
Oracle 중복된 데이터만 조회😉
select from table group by having절로 중복 데이터만 조회하는 건 아래처럼 조회하면 된다.
SELECT NAME, sum(1) hap
FROM TMP_220512 t
GROUP BY NAME
HAVING sum(1) > 1
;
결과는 아래처럼 name이 1개 이상인 중복데이터가 조회된다.
![[Oracle] Oracle 중복데이터 제거(feat. delete from table + group by having) - Oracle 중복된 데이터만 조회😉 [Oracle] Oracle 중복데이터 제거(feat. delete from table + group by having) - Oracle 중복된 데이터만 조회😉](https://blog.kakaocdn.net/dn/dTcQ2Z/btrSlVeLdG3/Km9xlKw799mFgVRuI8YT91/img.png)
문득 위의 중복된 데이터만 제거하고 싶어서 해봤다.
아래처럼 쿼리를 날리면 된다.(더 좋은 방법이 있을 수도 있다.)
테이블 상태(인덱스 존재 등)에 따라 오래 걸릴 수도 있다.
중복된 데이터만 제거😄
먼저 group by having절로 중복데이터가 1개 이상인 데이터만 뽑고
그걸 서브쿼리에 넣은 후 DELETE문으로 삭제
DELETE FROM TMP_220512 t2
WHERE NAME IN
(
SELECT NAME
FROM TMP_220512 t
GROUP BY NAME
HAVING sum(1) > 1
)
;
![[Oracle] Oracle 중복데이터 제거(feat. delete from table + group by having) - 중복된 데이터만 제거😄 [Oracle] Oracle 중복데이터 제거(feat. delete from table + group by having) - 중복된 데이터만 제거😄](https://blog.kakaocdn.net/dn/cwf9Ac/btrSkC1kGD0/WZKLxNdsR6sDxxqeZIfSJK/img.png)
내가 잊어버리지 않기 위해서 메모
![[Oracle] Oracle 중복데이터 제거(feat. delete from table + group by having) - 중복된 데이터만 제거😄 [Oracle] Oracle 중복데이터 제거(feat. delete from table + group by having) - 중복된 데이터만 제거😄](https://t1.daumcdn.net/keditor/emoticon/friends1/large/025.gif)
'IT > DataBase' 카테고리의 다른 글
[Oracle]ORACLE SYNOSYM(시노님-동의어) (0) | 2022.11.29 |
---|---|
[Oracle]ORACLE DELETE, TRUNCATE, DROP 차이 (0) | 2022.11.29 |
[Oracle] system 계정 비밀번호 만료/비밀번호 변경(feat. ORA-00988) (0) | 2022.11.28 |
[SQL] Oracle SELECT query 실행 순서 (1) | 2022.11.28 |
[PostGreSQL] 현재 실행중인 SQL 조회, 종료 (0) | 2022.11.28 |
댓글