- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Regex to find string and next character in a comma separated list - MySQL?
To search in a comma separated list, use MySQL find_in_set(). The usage of Regex for this purpose isn’t required here. The syntax is as follows −
select *from yourTableName where find_in_set(anyValue,yourColumnName);
Let us create a table −
mysql> create table demo17 −> ( −> id int not null auto_increment primary key, −> first_name varchar(50), −> value text −> ); Query OK, 0 rows affected (1.81 sec)
Insert some records into the table with the help of insert command −
mysql> insert into demo17(first_name,value) values('John','50'); Query OK, 1 row affected (0.11 sec) mysql> insert into demo17(first_name,value) values('David',''); Query OK, 1 row affected (0.13 sec) mysql> insert into demo17(first_name,value) values('Adam','50,89'); Query OK, 1 row affected (0.14 sec) mysql> insert into demo17(first_name,value) values('Adam','49,89,43'); Query OK, 1 row affected (0.20 sec)
Display records from the table using select statement −
mysql> select *from demo17;
This will produce the following output −
+----+------------+----------+ | id | first_name | value | +----+------------+----------+ | 1 | John | 50 | | 2 | David | | | 3 | Adam | 50,89 | | 4 | Adam | 49,89,43 | +----+------------+----------+ 4 rows in set (0.00 sec)
Following is the query to find string and next character −
mysql> select *from demo17 where find_in_set(50,value);
This will produce the following output −
+----+------------+-------+ | id | first_name | value | +----+------------+-------+ | 1 | John | 50 | | 3 | Adam | 50,89 | +----+------------+-------+ 2 rows in set (0.00 sec)
- Related Articles
- Convert a List of String to a comma separated String in Java
- Java Program to Convert a List of String to Comma Separated String
- Convert String into comma separated List in Java
- How to sum a comma separated string (string with numbers) in MySQL?
- Display MySQL Results as comma separated list?
- How to create a comma separated string from a list of string in C#?
- How to set a comma separated list as a table in MySQL?
- How to use a comma-separated string in an `IN ()` in MySQL?
- Remove specific word in a comma separated string with MySQL
- Check if value exists in a comma separated list in MySQL?
- How would you make a comma-separated string from a list in Python?
- How can I match a comma separated list against a value in MySQL?
- MySQL query to retrieve records from the part of a comma-separated list?
- MySQL query to get a single value from position of comma-separated string?
- Convert a Set of String to a comma separated String in Java

Advertisements