0

I have a table with purpose of holding id's. I want to select from other table ( a big table of millions of records) also many records.

Which one would outperform:

SELECT id, att1, att2 
FROM myTable 
WHERE id IN (SELECT id FROM @myTabwithIDS)

Or

SELECT id, att1, att2 
FROM myTable t
INNER JOIN @myTabwithIDS t2
    ON t2.id = t.id
edgarmtze
  • 24,683
  • 80
  • 235
  • 386

1 Answers1

1

I would use the Query Analyzer built in to SQL Server to explore the execution plan.

http://www.sql-server-performance.com/2006/query-analyzer/

Specifically turn on Show Execution Plan, and Statistics IO and Time.

Normally a join is better than a subquery, especially in your case where the outer queries condition depends on the results of the subquery (known as a correlated subquery). See Subqueries vs joins for more details.

Community
  • 1
  • 1
dnatoli
  • 6,972
  • 9
  • 57
  • 96