
- 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 search between comma separated values within one field?
Use FIND_IN_SET for this. Let us first create a table −
mysql> create table DemoTable -> ( -> ListOfValues text -> ); Query OK, 0 rows affected (0.56 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('10|20|30|40|50|60|100'); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+-----------------------+ | ListOfValues | +-----------------------+ | 10|20|30|40|50|60|100 | +-----------------------+ 1 row in set (0.00 sec)
Following is the query to search between comma separated values within one field −
mysql> select FIND_IN_SET(100, replace(ListOfValues,'|',',')) from DemoTable;
Output
This will produce the following output −
+-------------------------------------------------+ | FIND_IN_SET(100, replace(ListOfValues,'|',',')) | +-------------------------------------------------+ | 7 | +-------------------------------------------------+ 1 row in set (0.04 sec)
- Related Articles
- Can we use IN() to search between comma separated values within one field?
- How can I search within a table of comma-separated values in MySQL?
- How to search for particular strings between comma separated values in MySQL?
- Count values from comma-separated field in MySQL?
- MySQL query to fetch specific records matched from an array (comma separated values)
- Count boolean field values within a single MySQL query?
- MySQL query to get string from one column and find its position in another column with comma separated values?
- Can I search for particular numbers in a MySQL column with comma separated records using a MySQL query?
- Fetch records from comma separated values using MySQL IN()?
- How to fetch random rows in MySQL with comma separated values?
- MySQL query to find a value in a set of values separated by comma in a custom variable
- Find integer in text data (comma separated values) with MySQL?
- MySQL query to retrieve records from the part of a comma-separated list?
- MySQL query to get a single value from position of comma-separated string?
- MySQL database field type for search query?

Advertisements