我想删除此select查询返回的任何内容:
SELECT u.*
FROM (
SELECT userName, groupId, MAX(userId) AS maxId
FROM userTable
where userName <> '' and userName is not null
GROUP BY
userName, groupId
HAVING COUNT(*) > 1
) q
JOIN userTable u
ON u.userName = q.userName
AND u.groupId= q.groupId
AND u.userId <> q.maxId)
我该怎么做?
答案 0 :(得分:10)
按以下方式构建您的删除:
DELETE U
FROM U ...
JOIN Q ...
WHERE Foo ...
或者,如果你手头有一个漂亮的查询,你可以这样做:
DELETE Usertable WHERE userId IN (
SELECT UserID FROM ... /* big complex query here */
)
答案 1 :(得分:5)
只需将SELECT u.*
替换为DELETE U