title: AQL: Find all persons whose name occurs more than once and who are American
body: <p>In ArangoDB, I have a collection 'people'. Each person has a name and a nationality.
  How do I find the keys of all persons whose name occurs more than once and who are American?</p>
  
  <p>I can run both queries separately.
  Selecting all people whose name occurs more than once:</p>
  
  <pre><code>FOR p IN people
  LET key = p._key
  COLLECT p.name INTO groups KEEP key
  FILTER LENGTH(groups) &gt;= 2
  LET group = groups[*].key
  RETURN group
  </code></pre>
  
  <p>Selecting all people who are American:</p>
  
  <pre><code>FOR p IN people
  FILTER p.nationality == 'American'
  RETURN p._key
  </code></pre>
  
  <p>But I cannot figure out how to combine these two. The problem is that I need to filter for nationality <em>after</em> checking whether the name is non-unique (because there might be an American John Smith and a British John Smith).
  The COLLECT statement however creates a list of lists and I could not figure out how to filter it correctly.</p>