Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would prefer to use <code>IN</code> in this case as it would be better. However to check the performance you may try to look at the Execution Plan of the query which you are executing. You will get the idea about what performance difference you will get by using the both.</p> <p>Something like this:</p> <pre><code>SELECT id from users where collegeid IN ('1','2','3'....,'1000') </code></pre> <p>According to the <a href="http://dev.mysql.com/doc/refman/5.5/en/comparison-operators.html#function_in" rel="nofollow noreferrer">MYSQL</a> </p> <blockquote> <p>If all values are constants, they are evaluated according to the type of expr and sorted. The search for the item then is done using a binary search. <strong>This means IN is very quick if the IN value list consists entirely of constants.</strong></p> <p>The number of values in the IN list is only limited by the <strong><a href="http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_max_allowed_packet" rel="nofollow noreferrer">max_allowed_packet</a></strong> value.</p> </blockquote> <p>You may also check <a href="https://stackoverflow.com/questions/3074713/in-vs-or-in-the-sql-where-clause">IN vs OR in the SQL WHERE Clause</a> and <strong><a href="https://stackoverflow.com/questions/782915/mysql-or-vs-in-performance">MYSQL OR vs IN performance</a></strong></p> <p>The answer given by Ergec is very useful:</p> <pre><code>SELECT * FROM item WHERE id = 1 OR id = 2 ... id = 10000 </code></pre> <p>This query took <strong>0.1239 seconds</strong></p> <pre><code>SELECT * FROM item WHERE id IN (1,2,3,...10000) </code></pre> <p>This query took <strong>0.0433 seconds</strong></p> <h1>IN is 3 times faster than OR</h1> <blockquote> <p><strong>will it affect the speed or output in any way?</strong></p> </blockquote> <p>So the answer is <strong>Yes</strong> the performance will be affected.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload