February 2, 2010 at 12:21 pm
So someone pointed out an interesting discussion they ran across and now I was wondering about it:
DELETE grandchild
FROM grandchild gc
JOIN child c on c.child_id=gc.child_id
join parent p on p.parent = c.parent_id
vs.
DELETE grandchild gc
WHERE EXISTS
(SELECT *
FROM child c
JOIN parent p
ON c.parent_id = p.parent_id
WHERE gc.child_id = c.child_id
)
-crappy formatting there I know
Anyway, why would you use EXISTS over the more direct join?
February 2, 2010 at 3:25 pm
Your question is one that is often asked and debated. Check out this link:
http://www.sqlservercentral.com/Forums/Topic848551-360-1.aspx?Highlight=%22my+first+article%22
February 3, 2010 at 12:05 am
Because the join isn't necessary. All you're trying to do is find rows that exist in the other table. So why not use EXISTS?
One of these may have been the 'interesting discussion'
http://sqlinthewild.co.za/index.php/2010/01/12/in-vs-inner-join/
http://sqlinthewild.co.za/index.php/2009/08/17/exists-vs-in/
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply