I currently have a table:
id | name | type | type_name
----+-------+------+-----------
101 | John | 1 | cat
101 | John | 2 | dog
253 | Bill | 2 | dog
376 | Rick | 3 | giraffe
376 | Rick | 2 | dog
440 | James | 2 | dog
440 | James | 1 | cat
440 | James | 3 | giraffe
I want to build a new view that uses the data from the table. If a 'name'/'id' has more than one type, then the types column below would combine them:
Considering there are only three possible types,
combinedType:
1 = cat
2 = dog
3 = giraffe
4 = cat and dog
5 = cat and giraffe
6 = dog and giraffe
7 = cat, dog, and giraffe
id | name | combinedTypeID| newTypeName
-----+-------+---------------+------------------
101 | John | 4 | cat and dog
253 | Bill | 2 | dog
376 | Rick | 6 | dog and giraffe
440 | James | 7 | cat, dog, and giraffe
I've got brain fog on doing this without messy subqueries.
Thanks all!