Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否从sql server 2000中的选择中删除?_Sql_Select_Sql Server 2000_Sql Delete - Fatal编程技术网

是否从sql server 2000中的选择中删除?

是否从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查询返回的任何内容:

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