

- 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
Can I search for particular numbers in a MySQL column with comma separated records using a MySQL query?
Yes, you can search for particular numbers using the MySQL FIND_IN_SET(). Let us first create a table −
mysql> create table DemoTable ( ListOfNumbers varchar(100) ); Query OK, 0 rows affected (1.24 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('784,746,894,344'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('456,322,333,456'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('654,785,678,456'); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable values('123,676,847,785'); Query OK, 1 row affected (0.34 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-----------------+ | ListOfNumbers | +-----------------+ | 784,746,894,344 | | 456,322,333,456 | | 654,785,678,456 | | 123,676,847,785 | +-----------------+ 4 rows in set (0.00 sec)
Following is the query to search for particular numbers in a record −
mysql> select *from DemoTable where find_in_set('456',ListOfNumbers);
This will produce the following output −
+-----------------+ | ListOfNumbers | +-----------------+ | 456,322,333,456 | | 654,785,678,456 | +-----------------+ 2 rows in set (0.28 sec)
- Related Questions & Answers
- Find specific records from a column with comma separated values in MySQL
- How to search for particular strings between comma separated values in MySQL?
- How can I search within a table of comma-separated values in MySQL?
- Searching from a comma separated MySQL column?
- Fetch records from comma separated values using MySQL IN()?
- MySQL query to retrieve records from the part of a comma-separated list?
- How can I match a comma separated list against a value in MySQL?
- MySQL query to search between comma separated values within one field?
- MySQL query to select records with a particular date?
- MySQL query to select a row which contains same number in a column with set of numbers separated by comma?
- How to sum a comma separated string (string with numbers) in MySQL?
- How to include quotes in comma separated column with MySQL?
- Can I get Age using BirthDate column in a MySQL query?
- MySQL query to fetch specific records matched from an array (comma separated values)
- Remove specific word in a comma separated string with MySQL
Advertisements