gpt4 book ai didi

sql - SQL 查询如何有两个 from 子句?

转载 作者:行者123 更新时间:2023-12-02 10:06:42 24 4
gpt4 key购买 nike

这对我来说看起来很奇怪:

delete from GearsDev.dbo.Products 
from GearsDev.dbo.Products as C
inner join #Common as M
on M.item = C.ItemNumber

#Common 是一个临时表,但其余部分对我来说没有任何意义。

如何有两个 from 子句?

最佳答案

DELETE的文档可以看出,可能需要两个FROM条款。

第一个FROM :

FROM: Is an optional keyword that can be used between the DELETE keyword and the target table_or_view_name, or rowset_function_limited.

第二个FROM :

FROM <table_source>: Specifies an additional FROM clause. This Transact-SQL extension to DELETE allows specifying data from and deleting the corresponding rows from the table in the first FROM clause.

This extension, specifying a join, can be used instead of a subquery in the WHERE clause to identify rows to be removed.

因此,SQL 将从 Products 中删除记录当与 #common 连接时具有匹配项的表.

这相当于(在含义上)以下查询:

delete from [GearsDev].[dbo].[Products]
where ItemNumber in
(
select item from #common
)

关于sql - SQL 查询如何有两个 from 子句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8011197/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com