SQL-从SELECT查询中删除结果

时间:2018-08-22 17:57:44

标签: sql sql-server

我对链接服务器有一个SELECT语句,如下所示;

SELECT [TrackingId]
FROM  [Server1\DB].[sctracking].[dbo].[scTracking] AS A
WHERE EXISTS (SELECT * FROM [Server2\DB].[sctracking].[dbo]. [scTracking] AS B
WHERE A.Reserved = B.Reserved )

这给了我想要的输出,但是实际上我想要做的就是删除结果。

谁能建议我将删除语句包装到其中吗?

2 个答案:

答案 0 :(得分:1)

DELETE A FROM [Server1\DB].[sctracking].[dbo].[scTracking] A
WHERE EXISTS (SELECT *
              FROM [Server2\DB].[sctracking].[dbo]. [scTracking] AS B
WHERE A.Reserved = B.Reserved)

答案 1 :(得分:1)

改为使用DELETE语句:

DELETE A
FROM [Server1\DB].[sctracking].[dbo].[scTracking] AS A
WHERE EXISTS (SELECT 1 
              FROM [Server2\DB].[sctracking].[dbo].[scTracking] AS B
              WHERE A.Reserved = B.Reserved 
             );