This just looks so odd to me:
delete from GearsDev.dbo.Products
from GearsDev.dbo.Products as C
inner join #Common as M
on M.item = C.ItemNumber
#Common
is a temp table, but the rest of it makes no sense to me.
How can you have two from
clauses?
As can be seen from the documentation of DELETE, it can take two FROM clauses. The first 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.
The AND operator allows the existence of multiple conditions in an SQL statement's WHERE clause.
The SQL AND condition and OR condition can be combined to test for multiple conditions in a SELECT, INSERT, UPDATE, or DELETE statement. When combining these conditions, it is important to use parentheses so that the database knows what order to evaluate each condition.
As can be seen from the documentation of DELETE, it can take two FROM
clauses.
The first 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.
The second 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.
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
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With