Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@reyjrar
Created May 30, 2015 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reyjrar/9cc73b69881f7eb6915b to your computer and use it in GitHub Desktop.
Save reyjrar/9cc73b69881f7eb6915b to your computer and use it in GitHub Desktop.
Deletion with Aggregated Data
WITH dups AS(
select response_id, answer_id, section
from meta_answer
group by response_id, answer_id, section
having count(1) > 1
)
DELETE FROM meta_answer ma
WHERE EXISTS (
SELECT 1
FROM dups
WHERE dups.response_id = ma.response_id
AND dups.answer_id = ma.answer_id
AND dups.section = ma.section
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment