0706.sql

looggi·2023년 7월 5일
0

TILs

목록 보기
113/114
post-thumbnail

196. Delete Duplicate Emails

delete from person 
where id in (select tbl.id from (select p.id  
                              from (select * from person 
                                    order by email, id) p
                              group by p.email
                              having count(*)>1) tbl);

이게 왜 틀리지?????????????
https://www.lesstif.com/dbms/mysql-error-1093-you-can-t-specify-target-table-tablename-for-update-in-from-clause-18220088.html

먼가 프로그래머스에서는 걍 될 것 같은데 리코드라서 안되니ㅡㄴ 것 같고.. 그래.. ㅋㅋ

중복 제거하는 방법
https://yahwang.github.io/posts/79

# Write your MySQL query statement below
# delete from person 
# where id not in (select pp.id 
#                  from (select email, min(id) as id
#                        from person 
#                        group by email
#                        having count(*)>1) p, person pp
#                  where p.email=pp.email and p.id=pp.id)

# DELETE FROM person
# WHERE id IN (SELECT id
#              FROM ( 
#                  SELECT id, ROW_NUMBER() OVER (PARTITION BY email) as row_num
#                  FROM person
#                  ) tmp
#              WHERE row_num > 1);

DELETE FROM Person WHERE Id NOT IN 
(SELECT * FROM( SELECT MIN(Id) FROM Person GROUP BY Email) as p);

왜 계속 틀리는지 이해할 수 없음...

profile
looooggi

0개의 댓글