title: Using having count() in exists clause
body: <p>I am trying to make a SQL query where the subquery in an 'exists' clause has a 'having' clause. The strange thing is that. There is no error and the subquery works as a stand-alone query. However, the whole query gives exactly the same results with the 'having' clause as without.<br>
  This is kind of what my query looks like:</p>
  
  <pre><code> SELECT X
     FROM A
    WHERE exists (
                 SELECT X, count(distinct Y)
                   FROM B
               GROUP BY X
                 HAVING count(distinct Y) &gt; 2)  
  </code></pre>
  
  <p>So I'm trying to select the rows from A where X has more then two occurances of Y in B.
  However, the results also include records that do not exist in the subquery. What am I doing wrong here?</p>