title: How to use a WITH clause in conjuction with a WHERE clause
body: <p>I've got the following query which is not running:</p>
  
  <pre><code>with countf as (
      select nationid, count(*) as c from customer
      group by nationid
  ),
  maxf as ( select max(nationid) from customer )
  
  select c.customerid, c.nationid from customer c, countf cf, maxf m
  where c.nationid = cf.nationid
  and cf.c = m
  </code></pre>
  
  <p>The problem seems to be that <code>m</code> is a record instead of an Integer. However, if I run it as a subquery as follows:</p>
  
  <pre><code>cf.c = ( select max(nationid) from customer )
  </code></pre>
  
  <p>it works as expected. I presume that I'm using the with statement just not the intended way. Trying</p>
  
  <pre><code>cf.c in maxf
  </code></pre>
  
  <p>makes me assume that a table generated using <code>WITH</code> is just not supposed to be used in a <code>WHERE</code> clause. </p>
  
  <p>I know that there are other ways to get the same query using <code>all</code> for example. I'm really only interested how I'm supposed to use the with statement. Can I only use it to <code>SELECT</code> from it later on?</p>
  
  <p>Thanks in advance for any kind of help.</p>