I would like to SELECT
the people table but dynamically assign the appropriate hobbies.
Instead of people having hobbies like 'A' or 'B' and 'C', I want to SELECT
another table and get the appropriate hobby string.
One hobby is easy:
SELECT name, age,
(SELECT hobby
FROM hobbies
WHERE people.hobbies = hobbies.identifier) as hobbies
FROM people
But when I try to think of how to get multiple hobbies for a comma separated field and replace each identifier I reach a dead end. I tried to utilize STRING_SPLIT
, STRING_AGG
with no luck.
Any thoughts and/or ideas are most welcome!
Here is a fiddle with table definitions and sample data: