
- 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
Append wildcards in SELECT with MySQL?
For appending, use the concept of concat(). The syntax is as follows −
select *from yourTableName where yourColumnName like concat('%',yourValue,'%');
Let us create a table −
mysql> create table demo48 -> ( −> id int not null auto_increment primary key, −> name varchar(20) −> ); Query OK, 0 rows affected (0.70 sec)
Insert some records into the table with the help of insert command −
mysql> insert into demo48(name) values('John Smith'); Query OK, 1 row affected (0.12 sec) mysql> insert into demo48(name) values('John Doe'); Query OK, 1 row affected (0.12 sec) mysql> insert into demo48(name) values('Adam Smith'); Query OK, 1 row affected (0.23 sec) mysql> insert into demo48(name) values('David Miller'); Query OK, 1 row affected (0.14 sec) mysql> insert into demo48(name) values('Chris Brown'); Query OK, 1 row affected (0.11 sec)
Display records from the table using select statement −
mysql> select *from demo48;
This will produce the following output −
+----+--------------+ | id | name | +----+--------------+ | 1 | John Smith | | 2 | John Doe | | 3 | Adam Smith | | 4 | David Miller | | 5 | Chris Brown | +----+--------------+ 5 rows in set (0.00 sec)
Following is the query to append wildcards in select statement −
mysql> select *from demo48 where name like concat('%','Smith','%');
This will produce the following output −
+----+------------+ | id | name | +----+------------+ | 1 | John Smith | | 3 | Adam Smith | +----+------------+ 2 rows in set (0.00 sec)
- Related Articles
- Improve MySQL Search Performance with wildcards (%%)?
- Wildcards in column name for MySQL?
- How append string with select command in Android sqlite?
- Select with set order in MySQL
- MySQL select * with distinct id?
- Select and sum with grouping in MySQL?
- Select query with regular expression in MySQL
- Insert with a Select query in MySQL
- MySQL SELECT IF statement with OR?
- MySQL select query with multiple WHERE?
- SELECT a FLOAT with given precision in MySQL
- Select specific rows in a range with MySQL?
- Select records with ACTIVE status in MySQL set with ENUM
- MySQL - SELECT … WHERE id IN (..) order with particular column?
- Can we implement nested insert with select in MySQL?

Advertisements