Performance difference between Inner Join and Intersect commands

  • Everyone, I've recently become familiar with the 2005 Intersect command as a possible replacement for some inner join statements. I've seen a lot of articles comparing the syntax, but not much comparing the performance.

    Are there common situations where one command is generally superior to the other?

  • The reason there probably aren't that many articles comparing performance between the two is because they're meant to substitute one for the other. INTERSECT is meant to find the distinct values combining two queries. That's a very different goal than the INNER JOIN which is not finding distinct values, but values that simply match between two tables, derived or otherwise.

    As a matter of fact, it's worse than that since the INTERSECT operation requires that the values returned by both queries match in data type, so you couldn't even do a normal INNER JOIN operation between disparate tables using INTERSECT.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • as Grant stated the intersect is meanth to compare two sets of data, based on all columns of these sets.

    An inner join result set is only based on the matching columns mentioned in the ON clause, but will join both sets at row level (columns of table1 + columns of table2 will make one row).

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply