I want to do something like below:
DELETE UserPredictions
GROUP BY UserId
HAVING COUNT(*) < 500
But I\'m getting a syntax error. Is
I don't think that is possible however you can try this
Update : In
as well as inner join
can be used
Declare @Sample table
(
UserID int,
col2 int
)
INSERT INTO @Sample
SELECT 1,50 UNION ALL
SELECT 1,100 UNION ALL
SELECT 2,150 UNION ALL
SELECT 2,200 union all
Select 4,500
DeLETE FROM @Sample
WHERE UserID IN (SELECT UserID
FROM @Sample
GROUP BY UserID
HAVING COUNT(*) > 1)
Delete O
FROM @Sample O
INNER JOIN
(
SELECT UserID
FROM @Sample
GROUP BY UserID
HAVING COUNT(*) >1
) X
ON O.UserID = X.UserID
The answer which i originally posted :
Delete O
FROM UserPredictions O
INNER JOIN
(
SELECT UserID
FROM UserPredictions
GROUP BY UserID
HAVING COUNT(*) <500
) X
ON O.UserID = X.UserID