title: Select in a many-to-many relationship in MySQL
body: <p>I have two tables in a MySQL database, Locations and Tags, and a third table LocationsTagsAssoc which associates the two tables and treats them as a many-to-many relationship.</p>
  
  <p>Table structure is as follows:</p>
  
  <pre><code>Locations
  ---------
  ID int (Primary Key)
  Name varchar(128)
  
  LocationsTagsAssoc
  ------------------
  ID int (Primary Key)
  LocationID int (Foreign Key)
  TagID int (Foreign Key)
  
  Tags
  ----
  ID int (Primary Key)
  Name varchar(128)
  </code></pre>
  
  <p>So each location can be tagged with multiple tagwords, and each tagword can be tagged to multiple locations.</p>
  
  <p>What I want to do is select only Locations which are tagged with <strong><em>all of the tag names supplied</em></strong>. For example:</p>
  
  <p>I want all locations which are tagged with both "trees" and "swings". Location "Park" should be selected, but location "Forest" should not.</p>
  
  <p>Any insight would be appreciated. Thanks!</p>