这对我来说太奇怪了:
delete from GearsDev.dbo.Products from GearsDev.dbo.Products as C inner join #Common as M on M.item = C.ItemNumber#Common 是一个临时表,但其余部分对我来说毫无意义.
#Common is a temp table, but the rest of it makes no sense to me.
你怎么会有两个 from 子句?
How can you have two from clauses?
推荐答案从DELETE,可以带两个FROM子句.
第一个FROM:
来自:是一个可选关键字,可以在 DELETE 关键字和目标 table_or_view_name 或 rowset_function_limited 之间使用.
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 :指定附加的 FROM 子句.这个对 DELETE 的 Transact-SQL 扩展允许在第一个 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.
这个扩展指定了一个连接,可以用来代替 WHERE 子句中的子查询来标识要删除的行.
This extension, specifying a join, can be used instead of a subquery in the WHERE clause to identify rows to be removed.
因此,当使用#common 连接时,SQL 将从Products 表中删除具有匹配项的记录.
So, the SQL will delete records from the Products table that have a matching item when it is joined with #common.
这相当于(在含义上)以下查询:
This is equivalent (in meaning) to the following query:
delete from [GearsDev].[dbo].[Products] where ItemNumber in ( select item from #common )更多推荐
SQL 查询如何有两个 from 子句?
发布评论