title: Sql join two tables with having clause
body: <p>I have two tables</p>
  
  <pre><code>First_id | Text    Second_id | First_id | Date | Email
  </code></pre>
  
  <p>I need to get all records from first table having count from second table with date null and email null.</p>
  
  <p>I have sql: </p>
  
  <pre><code>Select * from first f join second s on f.id = s.first_id where date is null and email is null group by first_id having(count(s.id) &lt; 10 or count(s.id) = 0)
  </code></pre>
  
  <p>It works well, but where I have all data and email filled on second table for id from first table I got no result.</p>
  
  <p>Sample data:
  First table</p>
  
  <pre><code>1 | one
  2 | two
  </code></pre>
  
  <p>Second table</p>
  
  <pre><code>1 | 1 | NULL | NULL
  1 | 1 | 2015-01-01 | NULL
  1 | 2 | 2015-01-01 | NULL
  1 | 2 | 2015-01-01 | NULL
  </code></pre>
  
  <p>I expect on output: </p>
  
  <pre><code>1 | one | 1
  2 | two | 0
  </code></pre>
  
  <p>last column is count of entries from second with date and email NULL. My query returns</p>
  
  <pre><code>1 | one | 1
  </code></pre>
  
  <p>No second row</p>