title: MySQL number of items within "in clause"
body: <p>I have three tables to define users:</p>
  
  <pre><code>USER: user_id (int), username (varchar)
  USER_METADATA_FIELD: user_metadata_field_id (int), field_name (varchar)
  USER_METADATA: user_metadata_field_id (int), user_id (int), field_value (varchar)
  </code></pre>
  
  <p>I'd like to create a middle tier user that has certain access to other users within the application. To determine which users the logged in use can access, I am using a subquery like the following:</p>
  
  <pre><code>SELECT user_id FROM user WHERE user_id 
       IN (SELECT user_id 
           FROM user_metadata 
           WHERE user_metadata_field_id = 1 AND field_value = 'foo')
  </code></pre>
  
  <p>Currently I am storing the subquery string in a variable and then dynamically inserting it into the outer query each time I need to pull a list of users. After doing this I thought, "it has got to be better to just store  a string of the actual <code>user_id</code>s".</p>
  
  <p>So instead of storing this in a variable...</p>
  
  <pre><code>$subSql = "SELECT user_id FROM user_metadata WHERE user_metadata_field_id = 1 AND field_value = 'foo'";
  </code></pre>
  
  <p>... I actually perform the query and store the result like this...</p>
  
  <pre><code>$subSql = "12, 56, 89, 100, 1234, 890";
  </code></pre>
  
  <p>Then when I need to pull a lit of users that the logged in user has access to, I can do so with:</p>
  
  <pre><code>$sql = "SELECT user_id FROM user WHERE user_id IN ($subSql)";
  </code></pre>
  
  <p><strong>And finally the questions:</strong></p>
  
  <p>How many items can you use in a MySQL <code>IN</code> CLAUSE? Storing the actual ids instead of the sub-sql statement has got to be faster for performing that outer query each time, right?</p>