title: Select query with group by clause and multiple inner joins in Postresql
body: <p>I have 3 tabels with the following definitions</p>
  
  <pre><code>people
  ------
  - wid 
  - name
  
  types
  -----
  - guid
  - type
  
  mapping
  -------
  - guid
  - wid
  </code></pre>
  
  <p>The people table has the list of people</p>
  
  <p>The types table the type information for each row present in the people table. If a person belongs to more than one type, then two rows are present in the types table.</p>
  
  <p>The mapping table provides a mapping between people and types table.</p>
  
  <p>Now to find out who are the people of type 'politician' I can use the following query.</p>
  
  <pre><code>select name from people inner join 
  (mapping inner join types on mapping.guid = types.guid) 
  on people.wpid = mapping.wpid where types.type = 'politician'
  </code></pre>
  
  <p>But now I want to find out what are the other types a politician belongs. I know that I have to use <code>group by</code> and <code>having</code> clause. But I am not able to come up with the query. How to write this query?</p>