Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
MySQL LIKE query with dynamic array?
To implement LIKE query with dynamic array, the syntax is as follows −
Example
select *from yourTableName where yourColumnName2 like "%yourValue%" order by yourColumnName1 asc limit yourLimitValue;
Let us create a table −
Example
mysql> create table demo74 -> ( -> user_id int not null auto_increment primary key, -> user_names varchar(250) -> ) -> ; Query OK, 0 rows affected (0.67
Insert some records into the table with the help of insert command −
Example
mysql> insert into demo74(user_names) values("John Smith1,John Smith2,John Smith3");
Query OK, 1 row affected (0.18
mysql> insert into demo74(user_names) values("John Smith1");
Query OK, 1 row affected (0.15
mysql> insert into demo74(user_names) values("David Smith1");
Query OK, 1 row affected (0.12
mysql> insert into demo74(user_names) values("John Smith1,John Smith2,John Smith3,John Smith4");
Query OK, 1 row affected (0.10
Display records from the table using select statement −
Example
mysql> select *from demo74;
This will produce the following output −
Output
+---------+-------------------------------------------------+
| user_id | user_names |
+---------+-------------------------------------------------+
| 1 | John Smith1,John Smith2,John Smith3 |
| 2 | John Smith1 |
| 3 | David Smith1 |
| 4 | John Smith1,John Smith2,John Smith3,John Smith4 |
+---------+-------------------------------------------------+
Following is the MySQL LIKE query with dynamic array −
Example
mysql> select *from demo74 -> where user_names like "%John Smith1%" -> order by user_id asc -> limit 100;
This will produce the following output −
Output
+---------+-------------------------------------------------+
| user_id | user_names |
+---------+-------------------------------------------------+
| 1 | John Smith1,John Smith2,John Smith3 |
| 2 | John Smith1 |
| 4 | John Smith1,John Smith2,John Smith3,John Smith4 |
+---------+-------------------------------------------------+
3 rows in set (0.00 sec)
