Reputation: 241
case 1:
SELECT Column1, Cloumn2, Cloumn3 FROM TableName WHERE Column3 In (SELECT COL3 FROM #TempTable)
Case 2:
DECLARE @valueClo3 varchar(50) set @valueClo3 = 'AnyValue' SELECT Column1, Cloumn2, Cloumn3 FROM TableName WHERE Column3 In (@valueClo3)
Case 1 takes too much time(approx 3 min), while case 2 takes only 10 sec. #TempTable
has only one value 'AnyValue'
Upvotes: 1
Views: 95
Reputation: 51
Subqueries take a much longer time than any other choice. That being said, IN will be faster, but still functions as an 'or'.
I would recommend trying to join your temporary table. Based on your example, an inner join will will likely accomplish your goal.
Upvotes: 1