I'm trying to change the following query into one that deletes the returned rows.
SELECT bad_rows.*
FROM votes as bad_rows
INNER JOIN(
SELECT MIN(id) as min_id, votes.object_id, votes.user_id
FROM votes WHERE is_archived=FALSE AND
votes.direction < 20
GROUP BY votes.object_id, votes.user_id, votes.content_type_id
having COUNT(votes.object_id) > 1
) AS double_rows ON
double_rows.object_id = bad_rows.object_id
AND double_rows.user_id=bad_rows.user_id
AND bad_rows.is_archived=False
AND double_rows.min_id <> bad_rows.id
this select works and gives me the rows I want to delete. Now if i change the select into a delete my query does not work.
DELETE bad_rows.*
FROM votes as bad_rows
INNER JOIN(
SELECT MIN(id) as min_id, votes.object_id, votes.user_id
FROM votes WHERE is_archived=FALSE AND
votes.direction < 20
GROUP BY votes.object_id, votes.user_id, votes.content_type_id
having COUNT(votes.object_id) > 1
) AS double_rows ON
double_rows.object_id = bad_rows.object_id
AND double_rows.user_id=bad_rows.user_id
AND bad_rows.is_archived=False
AND double_rows.min_id <> bad_rows.id
ERROR: syntax error at or near "bad_rows" LINE 1: DELETE bad_rows.*