我正试图将以下查询更改为删除返回行的查询。
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
此选择有效,并为我提供要删除的行。现在,如果将select更改为delete,则查询将不起作用。
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
第1行:删除错误的行*