3

I have a field in my table like this:

fox,cat,bear,horse,dog

With FIND_IN_SET I can find if the value is in that string and get back the position of it. There is a way to get value of a determinate position?

for example:

position 3 = bear
position 2 = cat
Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76

1 Answers1

4

You can use substring_index twice in this way (change 2 to whichever item you want to extract):

select substring_index(substring_index(col, ',', 2), ',', - 1)
from t

Demo

Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76
  • Couldn't run the demo, it said "This language is for patrons only.". But you are my life saver. thx! – Meow Kim May 13 '22 at 04:22