

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL search and replace record from a list of records
Let us first create a table −
mysql> create table DemoTable -> ( -> ListOfName text -> ); Query OK, 0 rows affected (0.66 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Carol,Sam,John,David,Bob,Mike,Robert,John,Chris,James,Jace'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------------------------------------------------------------+ | ListOfName | +------------------------------------------------------------+ | Carol,Sam,John,David,Bob,Mike,Robert,John,Chris,James,Jace | +------------------------------------------------------------+ 1 row in set (0.00 sec)
Here is the query to search and replace a record from a list of records−
mysql> update DemoTable -> set ListOfName= -> concat(substring_index(ListOfName,'John',2) ,'Adam', SUBSTRING_INDEX(ListOfName, 'John', -1)); Query OK, 1 row affected (0.37 sec) Rows matched: 1 Changed: 1 Warnings: 0
Let us check the table records once again −
mysql> select *from DemoTable;
This will produce the following output −
+------------------------------------------------------------+ | ListOfName | +------------------------------------------------------------+ | Carol,Sam,John,David,Bob,Mike,Robert,Adam,Chris,James,Jace | +------------------------------------------------------------+ 1 row in set (0.00 sec)
- Related Questions & Answers
- Find and replace a part of URL records in MySQL?
- Perform search/replace for only the first occurrence of a character in MySQL table records?
- Exclude some ID records from a list and display rest in MySQL
- MySQL query to search record with apostrophe?
- Search and Replace in Python
- Find out the popular domains from a MySQL table with domain records and search volume
- Replace a specific duplicate record with a new value in MySQL
- How to find a specific record from a list of values with semicolon in MySQL?
- Order date records and fetch the 2nd ordered record in MySQL
- Replace records based on conditions in MySQL?
- How to search a record by date in MySQL table?
- MySQL query to retrieve records from the part of a comma-separated list?
- Fastest way to search for a date from the date records in MySQL
- Search records on the basis of date in MySQL?
- Get digits from a record in MySQL?
Advertisements