title: Mysql count and return just one row of data
body: <p>I need to count the amount of users that have have answered all of those 3 profile_options (so they have at least 3 records in the profile_answers table).</p>
  
  <pre><code>SELECT COUNT(DISTINCT(users.id)) users_count
  FROM users
  INNER JOIN profile_answers ON profile_answers.user_id = users.id
  WHERE profile_answers.profile_option_id IN (37,86,102) 
  GROUP BY users.id
  HAVING COUNT(DISTINCT(profile_answers.id))&gt;=3
  </code></pre>
  
  <p>The problem is that this query is return a table with rows for each user and how many they answered (in this case always 3). What I need is to return just one row that has the total number of users (so the sum of all rows of this example)</p>
  
  <p>I know how to do it with another subquery but the problem is that I am running into "Mysql::Error: Too high level of nesting for select"</p>
  
  <p>Is there a way to do this without the extra subquery?</p>
  
  <pre><code>SELECT SUM(sum_sub.users_count) FROM (
   (SELECT COUNT(DISTINCT(users.id)) users_count
   FROM users
   INNER JOIN profile_answers ON profile_answers.user_id = users.id
   WHERE profile_answers.profile_option_id IN (37,86,102) 
   GROUP BY users.id
   HAVING COUNT(DISTINCT(profile_answers.id))&gt;=3)
  ) sum_sub
  </code></pre>