가능한 중복 :
Remove Duplicate Rows Leaving Oldest Row Only?"post_title"필드가 다른 행에 복제 된 경우 테이블 행을 삭제하는 방법은 무엇입니까?
나는 필드 post_title
, post_id
, (그리고 문제가 그나마 일부 다른)가 posts_table 내 DB .. 에 posts_table
있습니다.
post_title이 다른 행에서 반복되는 경우 행 중 하나를 삭제해야합니다.
예 : 내가 중복 post_titles 모든 행을 삭제할 수있는 방법 내가 모든 중복 post_titles
SELECT post_title, COUNT(post_title) AS dup_count
FROM posts_table
GROUP BY post_title
HAVING (COUNT(post_title) > 1)
질문은 확인할 수 아래의 문장으로
posts_table
-------------------------------------------
post_id | post_title
-------------------------------------------
501 | Some post title here
502 | Another post title
503 | A test post tile
504 | Some post title here (this is duplicated, i need to delete this row)
505 | A different post title
? 이것에 대한
가장 빠른 쿼리는 다음과 같습니다
delete from posts_table where post_id in (
select post_id from (
select post_id from posts_table a group by post_title having count(post_title) > 1
) b
)
당신이 정말로 하나를 제외하고 모두, 또는 전부를 삭제 하시겠습니까? 그렇다면 어떤 것을 남기 나합니까? – CompanyDroneFromSector7G
또한 집계 및 비 집계 출력을 혼합 할 때 SQL이 작동하는지 의심 스럽습니다. – CompanyDroneFromSector7G
반복되는 행 중 하나를 삭제하고 다른 행을 삭제해야합니다. 삭제 된 행은 삭제되지 않습니다. 그리고 나는 당신이 "당신의 SQL"을 의미하는지 모르지만 그 문장은 post_title을 적절하게 검색하고 그것이 얼마나 많이 발견되었는지를 알고 있습니다. –