title: SQL WHERE ID IN (id1, id2, ..., idn)
body: <p>I need to write a query to retrieve a big list of ids.</p>
  <p>We do support many backends (MySQL, Firebird, SQLServer, Oracle, PostgreSQL ...) so I need to write a standard SQL.</p>
  <p>The size of the id set could be big, the query would be generated programmatically. So, what is the best approach?</p>
  <h3>1) Writing a query using IN</h3>
  <pre><code>SELECT * FROM TABLE WHERE ID IN (id1, id2, ..., idn)
  </code></pre>
  <p>My question here is. What happens if n is very big? Also, what about performance?</p>
  <h3>2) Writing a query using OR</h3>
  <pre><code>SELECT * FROM TABLE WHERE ID = id1 OR ID = id2 OR ... OR ID = idn
  </code></pre>
  <p>I think that this approach does not have n limit, but what about performance if n is very big?</p>
  <h3>3) Writing a programmatic solution:</h3>
  <pre><code>  foreach (var id in myIdList)
    {
        var item = GetItemByQuery(&quot;SELECT * FROM TABLE WHERE ID = &quot; + id);
        myObjectList.Add(item);
    }
  </code></pre>
  <p>We experienced some problems with this approach when the database server is queried over the network. Normally is better to do one query that retrieve all results versus making a lot of small queries. Maybe I'm wrong.</p>
  <p>What would be a correct solution for this problem?</p>