title: MySQL Select distinct rows with same id with different value in a column and excluded a specific value in another column
body: <p>I have a MySQL database table like following:</p>
  
  <pre><code>id   task_id     users
  1       1          1
  1       2          2
  2       1          2
  2       2          1
  2      10          1
  3       1          2
  3       2          2
  3       3          2
  4       1          2
  </code></pre>
  
  <p>I want to select id's who have multiple users. In this condition users 1 and 2 are valid. But the problem is, along with above condition I also wanted to select those who <strong>do not have a task_id = 10</strong>. So <em>final output should be id = 1.</em></p>
  
  <p>I achieved first condition fulfilled by the help of <a href="https://stackoverflow.com/questions/21162812/select-rows-with-same-id-but-different-value-in-another-column">this post.</a></p>
  
  <p>But could not achieved result excluding task_id = 10 because trying with following query, it is still showing both users 1 and 2.</p>
  
  <pre><code>select distinct t.id
  from table as t
  join (
      select id
      from table
      group by id
      having count(distinct users) &gt; 1
  ) as t2
  on t.id = t2.id
  AND task_id != 10
  </code></pre>