I want to check whether a integer value exists in a semi-comma separated string in a where clause like where index_of('123456;123;456','45')>0
as instr
dose but also checks the fully match of the integer value
Asked
Active
Viewed 207 times
1

Gordon Linoff
- 1,242,037
- 58
- 646
- 786

Aflext
- 309
- 4
- 15
1 Answers
1
Fix your data structure so you are not storing integers in strings and storing multiple values in a single column. This is not the SQL'ish way of storing data.
But, if you are stuck with someone else's really bad design decisions, then MySQL offers the convenient find_in_set()
:
where find_in_set(@intval, replace(STRINGCOL_YUCK, ';', ',')) > 0

Gordon Linoff
- 1,242,037
- 58
- 646
- 786
-
Thanks a lot. You saved me! – Aflext Apr 18 '17 at 04:10