
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Search for Particular Numbers in MySQL Column with Comma-Separated Records
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)
Advertisements