title: Group the rows that are having the same value in specific field in MySQL
body: <p>I am having the following data in MySQL table.</p>
  
  <pre><code>+--------+----------+------+
  | job_id | query_id | done |
  +--------+----------+------+
  |  15145 | a002     |    1 |
  |  15146 | a002     |    1 |
  |  15148 | a002     |    1 |
  |  15150 | a002     |    1 |
  |  15314 | a003     |    0 |
  |  15315 | a003     |    1 |
  |  15316 | a003     |    0 |
  |  15317 | a003     |    0 |
  |  15318 | a003     |    1 |
  |  15319 | a003     |    0 |
  +--------+----------+------+
  </code></pre>
  
  <p>I would like to know if it's possible to have a sql query, which can group by query_id <strong>IF ALL 'done' fields are marked as 1</strong>. The possible output I imagine would be:</p>
  
  <pre><code>+----------+------+
  | query_id | done |
  +----------+------+
  |  a002    |  1   |
  |  a003    |  0   |
  +----------+------+
  </code></pre>
  
  <p>I've tried the following SQL query:</p>
  
  <pre><code>select job_id, query_id, done from job_table group by done having done = 1 ;
  </code></pre>
  
  <p>But no luck.  I would really appreciate for any help!</p>