title: MySQL - Where/Having Count > columnName
body: <p>I have a list of dates called listings where people can signup to take part called a booking.</p>
  
  <pre><code>listings
  id |    date    | capacity
  1    2010-01-01   3
  2    2010-01-02   1
  3    2010-02-02   2
  
  bookings
  id | listing_id | name
  1    1            Chris
  2    1            Steve
  3    1            Allen
  4    2            Tracy
  </code></pre>
  
  <p>What I want to do is have a query which returns only the open listings based on the bookings.</p>
  
  <p>Query would only return the listing with id = 3. Since it has no bookings and a capacity of 2.</p>
  
  <pre><code>Sample query which won't work:
  SELECT
      *
  FROM
      listings
  HAVING COUNT(
               SELECT * FROM bookings WHERE listings.id=bookings.listing_id
              ) &lt; capacity
  </code></pre>
  
  <p>Any help is appreciated.</p>