Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
104 views
in Q2A Core by

Hey, I have many users who are only registered and they never vote, answer or ask questions on my qa . 

I want to delete users who never vote, answer, or question. 

Like- 

Select userid from qa_users where writeip='NULL'; 

I will use userid to delete users after fetching.

How to create a query to fetch? 

Never vote, answer and ask .

Q2A version: 1.8.2

1 Answer

+2 votes
by
selected by
 
Best answer

This query will give you the IDs of all users with no posts and no votes:

SELECT u.userid
FROM qa_users u
  LEFT JOIN qa_uservotes v ON u.userid = v.userid
  LEFT JOIN qa_posts p ON u.userid = p.userid
WHERE p.postid IS NULL AND v.postid IS NULL;

You don't need to fetch the IDs first, though. JOINs can be used in DELETE queries as well:

DELETE u
FROM qa_users u
  LEFT JOIN qa_uservotes v ON u.userid = v.userid
  LEFT JOIN qa_posts p ON u.userid = p.userid
WHERE p.postid IS NULL AND v.postid IS NULL;

by
Thank you! I have posted another question here https://www.question2answer.org/qa/95366/how-to-convert-title-to-slug-and-get-in-array-like-q2a
Please answer it.
...