I have 3 tabels with the following definitions
people
------
- wid
- name
types
-----
- guid
- type
mapping
-------
- guid
- wid
The people table has the list of people
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.
The mapping table provides a mapping between people and types table.
Now to find out who are the people of type 'politician' I can use the following query.
select name from people inner join
(mapping inner join types on mapping.guid = types.guid)
on people.wpid = mapping.wpid where types.type = 'politician'
But now I want to find out what are the other types a politician belongs. I know that I have to use group by
and having
clause. But I am not able to come up with the query. How to write this query?