Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any performance difference between a SQL "IN" statement versus using "OR"?

Thought I would ask the knowledgeable StackOverflow community a question that was on my mind today and I can't seem to find an answer.

Is there any performance difference or advantage between an "IN" or using "OR"?

Ie. Is

SELECT type FROM types WHERE typecat IN ('abc', 'def')

better than

SELECT type FROM types WHERE typecat = 'abc' OR typecat = 'def'

Adding: Using SQL Server 2008

like image 992
Mark Kadlec Avatar asked Apr 29 '10 19:04

Mark Kadlec


1 Answers

This depends entirely on the SQL product you're using, which you haven't stated. One RDBMS that I use regularly cannot use indexes for the OR version.

like image 145
Larry Lustig Avatar answered Sep 30 '22 12:09

Larry Lustig