Wednesday, March 7, 2012

please interpret this delete with 2 from clauses

I pretty much think I know what this does, but I've never seen a
DELETE statement with 2 FROM clauses:
delete from #acc
from ggg d
where #acc.id=d.nbr
and d.oid='294'
I think this is the same as
DELETE FROM #acc
WHERE #acc.id IN
(SELECT nbr FROM ggg d
WHERE d.oid ='294' )
but it never hurts to make sure :)On Sat, 30 Jun 2007 14:10:23 -0000, metaperl <metaperl@.gmail.com>
wrote:
>I pretty much think I know what this does, but I've never seen a
>DELETE statement with 2 FROM clauses:
>delete from #acc
> from ggg d
> where #acc.id=d.nbr
> and d.oid='294'
The first FROM is optional, and most examples in this group don't use
it.
>I think this is the same as
>DELETE FROM #acc
>WHERE #acc.id IN
> (SELECT nbr FROM ggg d
> WHERE d.oid ='294' )
Yes, that does the same thing. So does:
DELETE FROM #acc
WHERE EXISTS
(SELECT * FROM ggg d
WHERE d.oid ='294'
AND #acc.id = nbr )
>but it never hurts to make sure :)
Especially with DELETE!!! 8-)
Roy Harvey
Beacon Falls, CT

No comments:

Post a Comment