2

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)
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
hjwish.lee
  • 81
  • 1
  • 3
  • Normalize your schema. See ["Is storing a delimited list in a database column really that bad?"](https://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad) (Spoiler: Yes, it is.). – sticky bit Dec 22 '21 at 16:06

1 Answers1

0

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
Mureinik
  • 297,002
  • 52
  • 306
  • 350