
- 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 we use IN() to search between comma separated values within one field?
Instead of IN(), use FIND_IN_SET to search between comma separated values within one field. 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;
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;
This will produce the following output −
+-------------------------------------------------+ | FIND_IN_SET(100, replace(ListOfValues,'|',',')) | +-------------------------------------------------+ | 7 | +-------------------------------------------------+ 1 row in set (0.04 sec)
- Related Articles
- MySQL query 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?
- Can we use a comma between MySQL SELECT statements?
- How to split comma separated values in an R vector?
- Converting a comma separated string to separate arrays within an object JavaScript
- Fetch records from comma separated values using MySQL IN()?
- How to fetch random rows in MySQL with comma separated values?
- How to use a comma-separated string in an `IN ()` in MySQL?
- Find integer in text data (comma separated values) with MySQL?
- How to convert raw text to the CSV (Comma Separated Values) in PowerShell?
- Can I search for particular numbers in a MySQL column with comma separated records using a MySQL query?
- MySQL query to get string from one column and find its position in another column with comma separated values?
- How we can use Python Tuple within a Tuple?

Advertisements