

- 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
Remove specific word in a comma separated string with MySQL
Let us first create a table −
mysql> create table DemoTable836(FirstName SET('John','Chris','Adam')); Query OK, 0 rows affected (0.60 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable836 values('John,Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable836 values('John,Chris,Adam'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable836 values('Chris,Adam'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable836 values('John,Adam'); Query OK, 1 row affected (0.37 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable836;
This will produce the following output −
+-----------------+ | FirstName | +-----------------+ | John,Chris | | John,Chris,Adam | | Chris,Adam | | John,Adam | +-----------------+ 4 rows in set (0.00 sec)
Following is the query to remove a specific word in a comma-separated string −
mysql> update DemoTable836 set FirstName = FirstName &~ (1 << FIND_IN_SET('Chris', FirstName) - 1); Query OK, 3 rows affected (0.21 sec) Rows matched: 4 Changed: 3 Warnings: 0
Let us check the table records once again −
mysql> select *from DemoTable836;
This will produce the following output −
+-----------+ | FirstName | +-----------+ | John | | John,Adam | | Adam | | John,Adam | +-----------+ 4 rows in set (0.00 sec)
- Related Questions & Answers
- Find specific records from a column with comma separated values in MySQL
- How to sum a comma separated string (string with numbers) in MySQL?
- Finding a specific row which has several ids separated by comma in MySQL?
- Searching from a comma separated MySQL column?
- How to use a comma-separated string in an `IN ()` in MySQL?
- How to count specific comma separated values in a row retrieved from MySQL database?
- Find integer in text data (comma separated values) with MySQL?
- How to include quotes in comma separated column with MySQL?
- Regex to find string and next character in a comma separated list - MySQL?
- Convert a List of String to a comma separated String in Java
- Convert a Set of String to a comma separated String in Java
- Convert String into comma separated List in Java
- Display MySQL Results as comma separated list?
- MySQL query to fetch specific records matched from an array (comma separated values)
- Remove comma from a string in PHP?
Advertisements