title: MySQL syntax help needed
body: <p>I am completely stuck on this and would appreciate help from someone who is more fluent in sql than me!</p>
  
  <p>Situation: I have Images which can belong to up to 3 Categories. I have to look them up using the category name (e.g. 'School').  I have an Image table, a Category table, and a CategoryImage table as a join table</p>
  
  <p>The essential fields are</p>
  
  <pre><code>Category
      Id
      categoryname
  Image
      Id
      imagename
      description
  CategoryImage
      categoryId
      imageId
  </code></pre>
  
  <p>If Image '001' belongs to the categories called 'School' and 'Home' it will have 2 entries in CategoryImage.</p>
  
  <p>I need the sql to find all images which are in BOTH the 'School' AND the 'Home' category.  I can see that this sql is probably trying to return a single image where the category is 'School AND 'Home' which is clearly impossible.  [ Changing the AND to an OR finds images which be log to the 'School' category plus also images which belong to the 'Home' category, which is not what I need.</p>
  
  <pre><code>SELECT 
     DISTINCT t0.description, 
     t0.imagename
  FROM 
     Image t0, Category T2, CategoryImage T1 
  WHERE 
    (T2.name = "School" 
    AND T2.name = "Home")  
    AND T1.categoryId = T2.id 
    AND t0.id = T1.imageId 
  </code></pre>
  
  <p>Thanks in advance for any suggestions.</p>