
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- 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?
- 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?
- Regex to find string and next character in a comma separated list - MySQL?
- Searching from a comma separated MySQL column?
- How to include quotes in comma separated column with MySQL?
- Find integer in text data (comma separated values) with MySQL?
- MySQL query to fetch specific records matched from an array (comma separated values)
- Convert a List of String to a comma separated String in Java
- Convert a Set of String to a comma separated String in Java
- MySQL query to get a single value from position of comma-separated string?
- Convert String into comma separated List in Java
- How to fetch random rows in MySQL with comma separated values?

Advertisements