

- 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
How to find a specific record from a list of values with semicolon in MySQL?
For this, you can use FIND_IN_SET(). Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Value varchar(100) ); Query OK, 0 rows affected (2.49 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(Value) values('100;200;300'); Query OK, 1 row affected (0.42 sec) mysql> insert into DemoTable(Value) values('1;300;400'); Query OK, 1 row affected (0.58 sec) mysql> insert into DemoTable(Value) values('6;7;8;9;10'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable(Value) values('1;2;3;4;5'); Query OK, 1 row affected (9.36 sec) mysql> insert into DemoTable(Value) values('3;8;9;10'); Query OK, 1 row affected (0.46 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+-------------+ | Id | Value | +----+-------------+ | 1 | 100;200;300 | | 2 | 1;300;400 | | 3 | 6;7;8;9;10 | | 4 | 1;2;3;4;5 | | 5 | 3;8;9;10 | +----+-------------+ 5 rows in set (0.00 sec)
Following is the query to find a specific record from a list of values with a semicolon −
mysql> select *from DemoTable where find_in_set(8, replace(Value, ';', ',')) > 0;
This will produce the following output −
+----+------------+ | Id | Value | +----+------------+ | 3 | 6;7;8;9;10 | | 5 | 3;8;9;10 | +----+------------+ 2 rows in set (0.00 sec)
- Related Questions & Answers
- Fetch a specific record from a column with string values (string, numbers and special characters) in MySQL
- Find specific records from a column with comma separated values in MySQL
- MongoDB query to find a specific city record from a collection
- How to find a particular varchar id in MySQL from a list of values?
- How to get a specific column record from SELECT query in MySQL?
- Create a record array from a (flat) list of array and fetch specific values based on index in Numpy
- MySQL search and replace record from a list of records
- Replace a specific duplicate record with a new value in MySQL
- Implement specific record ordering with MySQL
- How do I exclude a specific record in MySQL?
- How to select a specific record from MySQL if date is in VARCHAR format?
- MySQL CONCAT a specific column value with the corresponding record
- MySQL query to select a record with two exact values?
- Program to find out the XOR values of specific elements from a generated list in Python
- Replace the empty values from a MySQL table with a specific value
Advertisements