A에는 있고, B에는 없는 대상을 찾는다.

그 결과를(A에만 있는영역)  A에서 삭제하는 쿼리

limit 으로 100,000만건씩 제거한다.

select table1 A 
left join table2 B 
on A.key = B.key
where B.key is NULL

 

delete 

  from table1

where col1 in

(

     select a.col1

       from table1 a

      left outer join table2 b

       on a.col1 = b.col1

       where b.col1 is null

       limit 100000

);

 

delete ~ limit 1 은 먹히지 않았다.

select 문으로 한번 감싸줘야 처리됨

 

 

 

A.col1 B.col1
12345 12345
34567 NULL
NULL 98765

 

12345는 A와 B 둘다 있다.

34567은 A에는 있고, B에는 없다. (==> 위 조건에서 삭제되어야 할 대상)

98765는 B에만 있다. A기준 left join이므로, 위 데이터는 포함되지 않음

 

 

 


--특정조건(2021년 1월이전)  limit으로 분할하여 update

update table1

set col3= null

where col1 in 

 (

    select col1 

       from table1

       where reg_date <'2021-01-01'

         and col3 is not null

        limit 200000

);

 


 

-- limit 으로 분할하여 삭제처리

delete 

  from table1

where data in (select data from table1 limit 50000);

'IT > SQL' 카테고리의 다른 글

[PostgrdSQL] WITH AS / CTE  (0) 2021.12.27
[PostgreSQL] 마지막 한달이내 접속일자  (0) 2021.12.27
[PostgreSQL] 월별,시간별 데이터 집계  (0) 2021.12.27
[PostgreSQL] row_number() 행번호  (0) 2021.12.27
[PostgreSQL] Decode  (0) 2021.12.27

+ Recent posts