

- 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
MySQL Select where values IN List string?
For this, use FIND_IN_SET().
Let us create a table −
Example
mysql> create table demo81 -> ( -> id int not null auto_increment primary key, -> username varchar(200) -> ); Query OK, 0 rows affected (1.44
Insert some records into the table with the help of insert command −
Example
mysql> insert into demo81(username) values('John,Chris,David'); Query OK, 1 row affected (0.11 mysql> insert into demo81(username) values('Mike,Sam'); Query OK, 1 row affected (0.14 mysql> insert into demo81(username) values('Chris,Bob,Sam'); Query OK, 1 row affected (0.13 mysql> insert into demo81(username) values('Mike,John,Chris'); Query OK, 1 row affected (0.23
Display records from the table using select statement −
Example
mysql> select *from demo81;
This will produce the following output −
Output
+----+------------------+
| id | username |+----+------------------+
| 1 | John,Chris,David || 2 | Mike,Sam |
| 3 | Chris,Bob,Sam || 4 | Mike,John,Chris |
+----+------------------+4 rows in set (0.00 sec)
Following is the query to select where values IN list string −
Example
mysql> select *from demo81 where find_in_set('Chris',username) > 0;
This will produce the following output −
Output
+----+------------------+
| id | username |+----+------------------+
| 1 | John,Chris,David || 3 | Chris,Bob,Sam |
| 4 | Mike,John,Chris |+----+------------------+
3 rows in set (0.03 sec)
- Related Questions & Answers
- SELECT where row value contains string in MySQL?
- SELECT WHERE IN null in MySQL?
- MySQL select query with multiple WHERE?
- MySQL Select Multiple VALUES?
- How do you select from MySQL where last value in a string = x?
- MySQL Select where value exists more than once
- MySQL Select where timestamp is in the current hour?
- SELECT * WHERE var == [one of many alternatives] in MySQL?
- MySQL randomly select 2 values from column values?
- SELECT a row by subtracting dates in WHERE in MySQL?
- Update with multiple values in MySQL WHERE clause
- Combine INSERT, VALUES, and SELECT in MySQL
- MySQL - SELECT … WHERE id IN (..) order with particular column?
- Concat a string to SELECT * in MySQL?
- Select timestamp as date string in MySQL?
Advertisements