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

编程入门 行业动态 更新时间:2024-10-20 16:08:55
本文介绍了SQL 查询如何有两个 from 子句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这对我来说太奇怪了:

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 子句?

本文发布于:2023-10-26 23:56:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531716.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子句   有两个   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!