2

Consider the following two queries:

Query 1

Select * from table where field = value1 OR field = value2 ... OR field = valueN

Query 2

Select * from table where field IN (value1, value2 , .... , valueN)

Are the two queries has same effect on the DB? or Is there an efficient way to do this?

vivek_jonam
  • 3,085
  • 8
  • 30
  • 42
  • 1
    They are identical. The final word on this has the execution plan – a_horse_with_no_name Feb 15 '13 at 09:46
  • They are not. The execution plan isn't the end of the story, and the evidence backs that up in [this duplicate question](http://stackoverflow.com/questions/782915/mysql-or-vs-in-performance), which finds some cases where `IN` is significantly faster. That said, the difference is unlikely to ever present a problem in reality. – Synchro Aug 13 '14 at 18:03

1 Answers1

3

No difference!!

Finally in Database internal

This query

Select * from table where field IN (value1, value2 , .... , valueN)

get converted into

Select * from table where field = value1 OR field = value2 ... OR field = valueN
Vishwanath Dalvi
  • 33,724
  • 39
  • 121
  • 151