Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+7 votes
1.3k views
in Q2A Core by
How to find duplicate questions and delete it?
by
What about using related questions list?
by
That is very time consuming
by
Do you want to keep the oldest question or the newest one? Does any of the duplicates you want to delete have answers?
by
I want to delete newest one with answer

1 Answer

0 votes
by

I don't really have an elegant solution for this, but something like the following might work (all untested, though, so take it with a grain of salt).

First you need to identify the IDs of the questions you want to keep:

SELECT min(postid)
FROM qa_posts
WHERE type='Q'
GROUP BY title;

Now you can delete answers to duplicate question by deleting posts with type "A" whose parent ID is not in that list:

DELETE FROM qa_posts
WHERE type='A' AND parentid NOT IN (
  SELECT min(postid)
  FROM qa_posts
  WHERE type='Q'
  GROUP BY title;
);

and duplicate questions by deleting post with type "Q" whose post ID is not in that list:

DELETE FROM qa_posts
WHERE type='Q' AND postid NOT IN (
  SELECT min(postid)
  FROM qa_posts
  WHERE type='Q'
  GROUP BY title;
);

by
Can I make a plugin with this?
by
Probably. If you want to go that route I'd recommend investing some more time into optimizing the queries, though. It should be possible to delete everything with a single query. Also, my answer does not address comments. You may want to consider those too if you make a plugin.
...