
- 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 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 Articles
- SELECT where row value contains string in MySQL?
- SELECT WHERE IN null in MySQL?
- How do you select from MySQL where last value in a string = x?
- MySQL Select Multiple VALUES?
- MySQL select query with multiple WHERE?
- Combine INSERT, VALUES, and SELECT in MySQL
- MySQL - SELECT … WHERE id IN (..) order with particular column?
- SELECT * WHERE var == [one of many alternatives] in MySQL?
- MySQL Select where timestamp is in the current hour?
- MySQL randomly select 2 values from column values?
- SELECT a row by subtracting dates in WHERE in MySQL?
- MySQL Select where value exists more than once
- Concat a string to SELECT * in MySQL?
- Select timestamp as date string in MySQL?
- Select distinct values from two columns in MySQL?

Advertisements