'A list with correlated countries

I have two tables The first one is similar to:

    | id | id_related     | 
    | id1| [id2, id3, id4]|
    | id2| [id1, id4]     |
    | id3| [id1, id2, id5]|

The second is similar to:

    |id | country |
    |id1| BR      |
    |id2| US      |
    |id3| CO      |
    |id4| IT      |
    |id5| US      |

I need a query that return:


   | id | id_related     | related_country |
   | id1| [id2, id3, id4]| [US, CO, IT]    |
   | id2| [id1, id4]     | [BR, IT]        |
   | id3| [id1, id2, id5]| [BR, US, US]    |

I trying to do a select with a select and concat, but nothing is working. Can someone help me?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source