0

I know that there are similar questions floating around (like SQL Filter criteria in join criteria or where clause which is more efficient) but as I remember SQL functions are special. Maybe? So basically which is more correct/more performant?

SELECT *
  FROM  [DBOne].[dbo].[SomeData] SD
    INNER JOIN [DBTwo].[DBOne].[SomeOtherData_GetALL]() SOD ON SD.[DataID] = SOD.[DataID]

OR

SELECT *
  FROM  [DBOne].[dbo].[SomeData] SD
  WHERE SD.[DataID] IN (SELECT [DataID] FROM [DBTwo].[DBOne].[SomeOtherData_GetALL]())
Community
  • 1
  • 1
Serj Sagan
  • 28,927
  • 17
  • 154
  • 183

2 Answers2

1

I usually use WHERE EXISTS instead of joining. See here for an explanation.

Community
  • 1
  • 1
Steve Dowling
  • 1,919
  • 1
  • 13
  • 18
0

Basically it is like asking JOIN vs SUB QUERY, if you are concern with the performance, i suggest to use the JOIN instead of using WHERE IN clause, you can see the difference of the performance if you use the execution plan of SQL.

To further understand, you can read this post: Join vs. sub-query

Hope this help.

Community
  • 1
  • 1
japzdivino
  • 1,736
  • 3
  • 17
  • 25
  • If this is true, then you'll get the check mark... but it seems people are saying that it doesn't matter... are you sure of this? – Serj Sagan Oct 08 '15 at 03:07
  • Actually using `SUB QUERY` is the simple and easiest way, but like what i've said if your concern is the performance itself, i am pretty sure it is better to use `JOIN` base on my experience in SQL. If you want to test you can use the execution plan of SQL for checking. – japzdivino Oct 08 '15 at 03:38