title: Query on JOIN tables
body: <p>I am working on an exercise for a databases class, but I am not able to finish the last exercise.</p>
  
  <p>The question is: Write a query that returns the name of all persons that like at least two people with green eyes. Eliminate duplicates from your query result.</p>
  
  <p>Two tables are given, namely : 
  Persons {<em>id</em>, name, address, age, eyeColor, gender} </p>
  
  <p>and </p>
  
  <p>Likes {<em>id</em>, personA_id → Persons, personB_id → Persons}</p>
  
  <p>The code that I have written is:</p>
  
  <pre><code>SELECT distinct P1.name, COUNT(P2.id)
  FROM Persons P1
  INNER JOIN Likes L
      On P1.id = L.PersonA_id
  INNER JOIN Persons P2
      ON P2.id = L.PersonB_id
  WHERE P2.eyeColor = "green" 
  AND COUNT(P2.id) &gt;= 2
  GROUP BY name
  </code></pre>
  
  <p>What do I have to do to make it work?       </p>
  
  <p>Thanks in advance,</p>