title: SQL query - select max where a count greater than value
body: <p>I've got two tables with the following structure:</p>
  
  <p><b>Question table</b><br/></p>
  
  <pre><code>id int, 
  question text, 
  answer text, 
  level int
  </code></pre>
  
  <p><b>Progress table</b><br/></p>
  
  <pre><code>qid int, 
  attempts int, 
  completed boolean (qid means question id)
  </code></pre>
  
  <p>Now my questions is how to construct a query that selects the max level where the count of correct questions is greater than let's say 30.</p>
  
  <p>I created this query, but it doesn't work and I don't know why.</p>
  
  <pre><code>SELECT MAX(Questions.level) 
  FROM Questions, Progress 
  WHERE Questions.id = Progress.qid AND Progress.completed = 1 
  GROUP BY  Questions.id, Questions.level 
  Having COUNT(*) &gt;= 30
  </code></pre>
  
  <p>I would like to have it in one query as I suspect this is possible and probably the most 'optimized' way to query for it. Thanks for the help!</p>