删除查询结果之外的所有内容

时间:2018-07-13 22:46:48

标签: sql

我想做的就是删除此查询不附带的所有内容:

Select Distinct PurchaseOrder.WellID, PurchaseOrder.JobiD, 
PurchaseOrderAccount.AccountCode, PurchaseOrder.PoNumber
From PurchaseOrder Join
PurchaseOrderAccount on PurchaseOrder.ID = PurchaseOrderAccount.PurchaseOrderID 

我尝试了很多事情。不幸的是我开始工作了。这是我尝试过的最后一件事:

Delete
from  PurchaseOrder
Where PurchaseOrder.ID

NOT IN (Select Distinct PurchaseOrder.ID
From PurchaseOrder Join
PurchaseOrderAccount on PurchaseOrder.ID = 
PurchaseOrderAccount.PurchaseOrderID 
)

1 个答案:

答案 0 :(得分:0)

我认为您可以做到:

Delete from PurchaseOrder
Where not exists (select 1
                  from PurchaseOrderAccount 
                  where PurchaseOrder.ID = PurchaseOrderAccount.PurchaseOrderID 
                 );