Use FIND_IN_SET() for command separated argument. Let us first create a table −
mysql> create table DemoTable604 (Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,Title varchar(100)); Query OK, 0 rows affected (0.51 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable604(Title) values('MySQL');
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable604(Title) values('C++');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable604(Title) values('MongoDB');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable604(Title) values('Java');
Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −
mysql> select *from DemoTable604;
This will produce the following output −
+----+---------+ | Id | Title | +----+---------+ | 1 | MySQL | | 2 | C++ | | 3 | MongoDB | | 4 | Java | +----+---------+ 4 rows in set (0.00 sec)
Here is the query for comma separated argument −
mysql> select *from DemoTable604 where find_in_set(Title,'C++,MongoDB');
This will produce the following output −
+----+---------+ | Id | Title | +----+---------+ | 2 | C++ | | 3 | MongoDB | +----+---------+ 2 rows in set (0.00 sec)