MSSql (Compact) DELETE-Query with JOIN



我有这个查询。我想从 AgentsResultLinks-Table 中删除所有实体,这些实体没有指向 Results-Table 中实体的链接。我想要一个只有一个查询的解决方案。我收到由"*"引起的错误。

DELETE AgentResultLinks.*
FROM AgentResultLinks LEFT JOIN Results 
ON AgentResultLinks.ResultID = Results.ID
WHERE Results.ID IS NULL

有人可以帮助我在紧凑数据库的 vaid mssql 查询中转换此查询吗?性能非常重要。

只需从AgentResultLinks.*中删除.*

DELETE Agent
FROM AgentResultLinks Agent 
LEFT JOIN Results R
       ON Agent.ResultID = R.ID
WHERE R.ID IS NULL;

请参阅DELETE语法:删除 (Transact-SQL)

请参见 SQLFiddle 示例

DELETE FROM AgentResultLinks 
where ResultID not in(select distinct ID from Results)

最新更新