views:

75

answers:

2

Hi, I have a database with only one table as below:

userurltag(id,userID(string),Url(String),tag(String))

I want to delete users that have less than 3 urls associated with them. How can I do that?

A: 
DELETE 
FROM userurltag 
WHERE UserID IN 
(SELECT UserID FROM userurltag GROUP BY userID Having COUNT(UserID) < 3)
Leslie
+2  A: 

Try this one:

DELETE
    FROM userurltag USING userurltag
    JOIN
        (SELECT userID
         FROM userurltag
         GROUP BY userID HAVING COUNT(*) < 3) as tmp
ON userurltag.userID = tmp.userID;
newtover
Replace "user_id" with "userid" and "t.userid" with "userurltag.userid" and this should work.
Ike Walker
@Ike Walker: you are right, I played with a slightly different table structure and did not modify the query thoroughly =)
newtover