title: SQL Filtering Through Multiple Tags
body: <p>I have three tables, images, tags and links(the table below) </p>
  
  <pre><code>   ImageNO | TagNO
       1     | Sport
       2     | Cars
       3     | Sport
       4     | Sport
       3     | Cars
       1     | Music
       2     | Sport
  </code></pre>
  
  <p>(Obviously TagNO would be a number in the actual table)</p>
  
  <p>What I want to do is allow filtering such that users can select any number of tags and images will be filtered to only the images with all of the tags chosen. For example if a user selects "sport", "imageNO" 1, 3 , 4 and 2 would be displayed. If the user also selects "cars" the query is refined and only "imageNO" 3 and 2 will be displayed.</p>
  
  <p>I have tried a number of things so far from examples across the web, this is the closest i have come to... </p>
  
  <pre><code>SELECT *
   FROM  images 
    LEFT JOIN links 
     ON INO = links.INO
    LEFT JOIN tags 
     ON tags.TagNO = links. TagNO
    WHERE links. TagNO
    IN ($tags)
    GROUP BY INO
    HAVING COUNT( INO ) &gt;1
  </code></pre>
  
  <p>($tags) is an array of tag numbers.</p>
  
  <p>The problem with this is an image with only one tag will never be displayed as the count number is = 1 not > 1. Any help would be much appreciated, thanks in advance.</p>