How to use query result text as another query's where condition at once?

Viewed 22

In those 2 tables

Table A [id, items]
        [1, "a,b,c"]

Table B [id , contents]
        ["a", apple]
        ["b", banana]

I want to get result as [apple, banana] at once like query

select contents from B where B.id in ("a","b","c")

or like

select contents from B where B.id in (select A.items from A where id = 1)
1 Answers

You can join the two tables with the find_in_set function:

SELECT contents
FROM   b
JOIN   a ON FIND_IN_SET(b.id, a.items) > 0
WHERE  a.id = 1
Related