

- 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 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 Questions & Answers
- 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
- Searching from a comma separated MySQL column?
- Display MySQL Results as comma separated list?
- 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?
- How to set a comma separated list as a table in MySQL?
- Count values from comma-separated field in MySQL?
- How to create a comma separated string from a list of string in C#?
- MySQL db query to fetch records from comma separate values on the basis of a specific value
- How to display data from a MySQL column separated by comma?
- MySQL query to search between comma separated values within one field?
- Check if value exists in a comma separated list in MySQL?
Advertisements