是否从sql server 2000中的选择中删除?
我想删除此select查询返回的任何内容:是否从sql server 2000中的选择中删除?,sql,select,sql-server-2000,sql-delete,Sql,Select,Sql Server 2000,Sql Delete,我想删除此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 C
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)
如何执行此操作?按如下方式构造删除:
DELETE U
FROM U ...
JOIN Q ...
WHERE Foo ...
或者,如果您手头已经有一个spiffy查询,您可以这样做:
DELETE Usertable WHERE userId IN (
SELECT UserID FROM ... /* big complex query here */
)
按如下方式构造删除:
DELETE U
FROM U ...
JOIN Q ...
WHERE Foo ...
或者,如果您手头已经有一个spiffy查询,您可以这样做:
DELETE Usertable WHERE userId IN (
SELECT UserID FROM ... /* big complex query here */
)
只需将SELECT u.*替换为DELETE u只需将SELECT u.*替换为DELETE u