title: mysql count and join 4 tables
body: <p>I have the following table structure:</p>
  
  <p>Table <em>folder</em><br>
  <code>id | title | is_hidden</code>  </p>
  
  <p>Table <em>object</em><br>
  <code>id | name | is_hidden | folder_id</code></p>
  
  <p>Table <em>label</em><br>
  <code>id | name</code></p>
  
  <p>Table <em>label_to_folder</em><br>
  <code>id | label_id | folder_id</code></p>
  
  <ul>
  <li>Each object <strong>always</strong> belongs to a folder.  </li>
  <li>Each folder <strong>may</strong> belong to one or more labels (this is defined by the <code>label_to_folder</code> table)</li>
  </ul>
  
  <p>I'm trying to get the most used (popular) labels, and I achieve it (I think :P) with the following query:
  <code>SELECT COUNT(lf.label_id) AS cnt, lf.label_id, l.name FROM label_to_folder lf JOIN label l ON lf.label_id=l.id  GROUP BY lf.label_id ORDER BY cnt DESC limit 8</code>  </p>
  
  <p>What I'm having trouble with, is extent the above query so it does not count hidden folders (folder.is_hidden=1) or empty folders (an empty folder is one with no objects at all or all the folder's objects are hidden)  </p>
  
  <p>Any help appreciated.</p>
  
  <p><strong>EDIT</strong>  </p>
  
  <p>sqlfiddle: <a href="http://sqlfiddle.com/#!9/65526/1" rel="nofollow">http://sqlfiddle.com/#!9/65526/1</a>
  The result there includes folder with id 5, but all its folders are empty - that's what I'm trying to eliminate.</p>