I want a query in SQL that change all 'a' in string to 'b' in first_name column in name table. Here is my columns name: first_name | list_name
Asked
Active
Viewed 5.4k times
2 Answers
51
use REPLACE()
UPDATE tableName
SET first_name = REPLACE(first_name, 'a', 'b')
but remember that REPLACE()
is case sensitive.

John Woo
- 258,903
- 69
- 498
- 492
-
1https://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_replace – feeela May 02 '13 at 09:45
-
is there another function that is not case sensitive ?, or a parameter we can pass to REPLACE ? – Francisco Corrales Morales Sep 22 '14 at 21:19
7
You can try this:
UPDATE name SET first_name = REPLACE (first_name, 'a', 'b') WHERE blabla LIKE '%blabla%';
OR
UPDATE name SET first_name = REPLACE (first_name, 'a', 'b') WHERE blabla = 'blabla';