The title might have been a bit confusing but I can clarify here.
I’m trying to use mysql’s LIKE to match a value that sometimes is surrounded by a : or sometimes it can be on one side, or sometimes neither. I know of the wildcard % but that will select everything, so I found the _ which would work but it ALWAYS select that single character, I want to only select that character if it is a : otherwise not.
Still confused? Here’s an example.
Say I got a column called ‘name’ in the table ‘que’ and in the column ‘name’ I got a value of ‘sdfgsdfgsdfg:jimmy:asfds’ I want to select ‘:jimmy:’ but if instead the value was ‘sdfgsdfgsdfg:jimmy’ I want to select ‘:jimmy’ only.
Another example.
To acomplish this with regular expressions it would be like this (:?)jimmy(:?) if that helps.
Whats the purpose?
I want to remove jimmy from that value and replace it with a :
I’m trying to store Multiple name into one column and need to remove that one person.
I got something like this so far:
UPDATE `que` SET `name`= CASE WHEN `name` LIKE '%jimmy%' THEN replace(`name`, '%jimmy%', ':') ELSE `name` end WHERE 1
So use
REGEXP?Don’t do that. Use your RDBMS’s relational capabilities and normalise your schema:
You would then remove all
jimmywith:If so desired, you could then retrieve your existing table as follows: