
- 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
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 Articles
- 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?
- Fetch records from comma separated values using MySQL IN()?
- Searching from a comma separated MySQL column?
- MySQL query to retrieve records from the part of a comma-separated list?
- MySQL query to select a row which contains same number in a column with set of numbers separated by comma?
- MySQL query to search between comma separated values within one field?
- MySQL query to select records with a particular date?
- How can I match a comma separated list against a value in MySQL?
- How to sum a comma separated string (string with numbers) in MySQL?
- How to include quotes in comma separated column with MySQL?
- MySQL query to fetch specific records matched from an array (comma separated values)
- Can I get Age using BirthDate column in a MySQL query?
- MySQL query to select records with a particular date and time?

Advertisements