
- 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
MySQL query to retrieve records from the part of a comma-separated list?
To retrieve records from the part of a comma-separated list, you can use built in function FIND_IN_SET().
Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(20), Marks varchar(200) ); Query OK, 0 rows affected (0.61 sec)
Following is the query to insert some records in the table using insert command −
mysql> insert into DemoTable(Name,Marks) values('Larry','98,34,56,89'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(Name,Marks) values('Chris','67,87,92,99'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(Name,Marks) values('Robert','33,45,69,92'); Query OK, 1 row affected (0.22 sec)
Following is the query to display records from the table using select command −
mysql> select *from DemoTable;
This will produce the following output −
+----+--------+-------------+ | Id | Name | Marks | +----+--------+-------------+ | 1 | Larry | 98,34,56,89 | | 2 | Chris | 67,87,92,99 | | 3 | Robert | 33,45,69,92 | +----+--------+-------------+ 3 rows in set (0.00 sec)
Following is the query to retrieve records from the part of a comma separated list. Here, we are getting the records of a student with marks 99 −
mysql> select Id,Name from DemoTable where find_in_set('99',Marks) > 0;
This will produce the following output −
+----+-------+ | Id | Name | +----+-------+ | 2 | Chris | +----+-------+ 1 row in set (0.00 sec)
- Related Articles
- MySQL query to fetch specific records matched from an array (comma separated values)
- Fetch records from comma separated values using MySQL IN()?
- MySQL query to get a single value from position of comma-separated string?
- Find specific records from a column with comma separated values in MySQL
- MySQL query to retrieve current date from a list of dates
- Can I search for particular numbers in a MySQL column with comma separated records using a MySQL query?
- Searching from a comma separated MySQL column?
- Display MySQL Results as comma separated list?
- MySQL db query to fetch records from comma separate values on the basis of a specific value
- How to set a comma separated list as a table in MySQL?
- MySQL query to search between comma separated values within one field?
- How to display data from a MySQL column separated by comma?
- How to create a comma separated string from a list of string in C#?
- Count values from comma-separated field in MySQL?
- Check if value exists in a comma separated list in MySQL?

Advertisements