- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- 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 use a comma-separated string in an `IN ()` in MySQL?
Set the comma-separated string in the IN() as in the below syntax:
select *from yourTableName where yourColumnName IN('yourCommaSeparatedValue');
Let us first create a table −
mysql> create table DemoTable1314 -> ( -> Number varchar(100) -> ); Query OK, 0 rows affected (0.53 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1314 values('45,67,89'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1314 values('10,20,50'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1314 values('90,56,45'); Query OK, 1 row affected (0.23 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable1314;
+----------+ | Number | +----------+ | 45,67,89 | | 10,20,50 | | 90,56,45 | +----------+ 3 rows in set (0.00 sec)
Following is the query to use a comma-separated string in MySQL `IN ()`:
mysql> select *from DemoTable1314 where Number IN('10,20,50');
+----------+ | Number | +----------+ | 10,20,50 | +----------+ 1 row in set (0.02 sec)
- How to sum a comma separated string (string with numbers) in MySQL?
- How to convert a comma separated String into an ArrayList in Java?
- Remove specific word in a comma separated string with MySQL
- Regex to find string and next character in a comma separated list - MySQL?
- How to create a comma separated string from a list of string in C#?
- Convert a List of String to a comma separated String in Java
- Convert a Set of String to a comma separated String in Java
- How to set a comma separated list as a table in MySQL?
- How to include quotes in comma separated column with MySQL?
- How to split comma separated values in an R vector?
- How to fetch random rows in MySQL with comma separated values?
- Convert String into comma separated List in Java
- MySQL query to get a single value from position of comma-separated string?
- Count values from comma-separated field in MySQL?