title: How to apply criteria to subquery (MySQL)
body: <p>As is happens, after I composed my question I found the solution. Here is what I had as problem:</p>
  <p>My database tables are:</p>
  <p><strong>bookings</strong> with such fields:
  id, event_id, ...</p>
  <p><strong>comments</strong> with such fields:
  id, booking_id, event_id</p>
  <p>and <strong>events</strong> obviously with ID and other fields. Also <strong>cities</strong> which is not important for this topic</p>
  <p>I have such working request:</p>
  <pre><code>SELECT
      bookings.id as 'booking id',
      bookings.name as 'client name',
      events.title as 'event title',
      cities.title as 'City',
  FROM bookings 
      JOIN events ON events.id = bookings .event_id 
      JOIN cities on events.city_id = cities.id
  WHERE bookings.status = &quot;new&quot;
  and bookings.id not in (SELECT booking_id 
                          FROM comments 
                          WHERE booking_id &lt;&gt; 0 
                          and booking_id is not null
                          )
  </code></pre>
  <p><strong>I want to see bookings for such events which have less than 5 comments</strong> in <strong>comments</strong> table.
  I was trying to add this (to query mentioned above):</p>
  <pre><code>SELECT
  &lt;...&gt;
  events.id as MY_VARIABLE 
  &lt;...&gt;
  WHERE
  &lt;...&gt;
  and (SELECT count(id) FROM comments WHERE comments.event_id = MY_VARIABLE and booking_id &lt;&gt; 0 and booking_id is not null) &lt; 10
  </code></pre>
  <p>This, obviously, DOES NOT WORK, and I don't know if I should make python script which will store count of comments for each event and then use this as criteria to exclude/include data from my first query</p>
  <p>Please help, is there easy enough solution in MySQL? I can provide additional info or make this more clear in comments, if needed</p>