
- 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
SELECT where row value contains string in MySQL?
To select the row value containing string in MySQL, use the following syntax.
SELECT *FROM yourTableName where yourColumnName like ‘%yourPattern%’;
To understand the above syntax, let us first create a table. The query to create a table is as follows.
mysql> create table PatternDemo -> ( -> Id int, -> Name varchar(100), -> Age int -> ); Query OK, 0 rows affected (0.97 sec)
Insert records in the table using insert command. The query is as follows.
mysql> insert into PatternDemo values(1,'James',23); Query OK, 1 row affected (0.11 sec) mysql> insert into PatternDemo values(2,'Joseph',21); Query OK, 1 row affected (0.18 sec) mysql> insert into PatternDemo values(3,'Robert',20); Query OK, 1 row affected (0.11 sec) mysql> insert into PatternDemo values(4,'John',26); Query OK, 1 row affected (0.10 sec) mysql> insert into PatternDemo values(5,'Richard',24); Query OK, 1 row affected (0.17 sec)
Now you can display all records from the table using select statement. The query is as follows.
mysql> select *from PatternDemo;
The following is the output.
+------+---------+------+ | Id | Name | Age | +------+---------+------+ | 1 | James | 23 | | 2 | Joseph | 21 | | 3 | Robert | 20 | | 4 | John | 26 | | 5 | Richard | 24 | +------+---------+------+ 5 rows in set (0.00 sec)
Here is the query that will give all names with the characters “Jo”. The query is as follows.
mysql> select *from PatternDemo where Name like '%Jo%';
The following is the output.
+------+--------+------+ | Id | Name | Age | +------+--------+------+ | 2 | Joseph | 21 | | 4 | John | 26 | +------+--------+------+ 2 rows in set (0.00 sec)
- Related Articles
- MySQL Select where values IN List string?
- SELECT a row by subtracting dates in WHERE in MySQL?
- How do you select from MySQL where last value in a string = x?
- How to select a row where one of several columns equals a certain value in MySQL?
- MySQL Select where value exists more than once
- MySQL query to check if a string contains a value (substring) within the same row?
- Select MySQL rows where column contains same data in more than one record?
- Select from table where value does not exist with MySQL?
- How to select row when column must satisfy multiple value in MySQL?
- Select a random row in MySQL
- MySQL query to select column where value = one or value = two, value = three, etc?
- SELECT WHERE IN null in MySQL?
- MySQL SELECT products WHERE 'average price per product' < value?
- How to select last row in MySQL?
- How to select data in MySQL where a field has a minimum value?

Advertisements