title: SQL EXISTS operator with GROUP BY
body: <p>I am currently looking through the EXISTS operator examples on <a href="http://www.w3resource.com/sql/special-operators/sql_exists.php#" rel="nofollow noreferrer">http://www.w3resource.com/sql/special-operators/sql_exists.php#</a> and have come across an example which doesn't quite make sense. The code is as follows:</p>
  
  <pre><code>SELECT cust_code,cust_name,cust_city,grade  
  FROM customer  
  WHERE grade=2 AND  
      EXISTS(  
          SELECT COUNT(*)
          FROM customer  
          WHERE grade=2  
          GROUP BY grade  
          HAVING COUNT(*)&gt;2
      );
  </code></pre>
  
  <p>From my understanding, the subquery will always evaluate to TRUE and it doesn't relate to the customer table higher up - so it seems irrelevant to put it in there.</p>
  
  <p>Can anybody explain what the code is trying to achieve here please?</p>
  
  <p>Many Thanks!</p>