I have this
UPDATE table SET example = REPLACE(example, '1', 'test') WHERE example REGEXP '1$'
So this code replaces all instances of "1" in the "example" field with "test".
I want to repeat this for 2, 3, 4 and so on.
But it would be very inefficient to use separate querys.
Is the any way I can do this with just one query?
Thanks
Using the REPLACE() function will allow you to change a single character or multiple values within a string, whether working to SELECT or UPDATE data.
MySQL REPLACE() Function The REPLACE() function replaces all occurrences of a substring within a string, with a new substring. Note: This function performs a case-sensitive replacement.
Answer: REPLACE INTO command can be used to replace an entire row in MySQL. The row is matched against the table's PRIMARY KEY, and if the key match is successful, then the row is replaced.
Matryoshka-way ;-)
REPLACE(REPLACE(REPLACE(example, '3', 'test') , '2', 'test') , '1', 'test')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With