
- 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 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)
- Related Articles
- Find the records with % character in a LIKE query with MySQL
- Query for implementing MySQL LIKE as MySQL IN?
- Implement Dynamic SQL query inside a MySQL stored procedure?
- MySQL query for text search with LIKE and OR to fetch records
- MySQL query to find same value on multiple fields with LIKE operator?
- How to query MongoDB with “like”?
- Create a dynamic table name from current year in MySQL like 2019
- Using LIKE clause twice in a MySQL query
- Combine columns before matching it with LIKE in a single query in MySQL?
- Can we use “LIKE concat()” in a MySQL query?
- Implement multiple LIKE operators in a single MySQL query
- How to use MySQL LIKE query to search a column value with % in it?
- MySQL query to display records from a table filtered using LIKE with multiple words?
- MySQL query to SELECT rows with LIKE and create new column containing the matched string?
- Implement SELECT LIKE and CHAR_LENGTH() in a single MySQL query
