I have a table that has a column with strings formatted like this: {1,4,5}
. They can be any length and I'd like to join an ID table against any value that has its ID in that string.
This is the first table
name id count
apple {1,3,6} 5
orange {5,3,1} 3
potato {8,1,9} 3
This is the second table -
id2 category
1 foo
2 foobar
3 candy
4 candybar
5 oreo
6 pistachio
I'd like a row for every ID listed in the first table that has the category from the second table. I'd like them to look like this -
id2 name id count
1 apple {1,3,6} 5
1 orange {5,3,1} 3
1 potato {8,1,9} 3
3 apple {1,3,6} 5
3 orange {5,3,1} 3
8 potato {8,1,9} 3
9 potato {8,1,9} 3
This is what I've got so far. Can I have a join filter that says join if the value is included
?
select id2, name, id, count
from table2 as t2
left join table1 as t1
on t2.id2 %in% t1.id