I have to compare a column value with a user input numbers. The string in the column is in the format 8|5|12|7|
Now, I need to compare a user input values 2
,5
,3
with this column value
When I use LIKE operator as '%2|%'
I got the output by matching with column value |12|
How do I match the string by using Regular Expression
or any other way?
If I understand the question correct, then to make sure that you get
2|..
or..|2|..
or|2
, you need to addor
clausesIt is bad design to build "arrays" in a cell. Use a separate table.
Anyway,
FIND_IN_SET()
is a function that does the work a lot easier than a regexp. (But you have to use ',')Something similar to this to test for
2
in this example12|8|12|5|12|7|2|12|22
REGEXP "(^|\|)2(\||$)"
This allows for the column value to just be
2
or2|anything
oranything|2
orfirst thing|2|end thing
.By looking your column design, one of the way u can do is
LIKE '%|2|%'