
- 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
How to use MySQL LIKE clause to fetch multiple values beginning with “Johâ€
Let us first create a table −
mysql> create table DemoTable ( Name varchar(40) ); Query OK, 0 rows affected (0.55 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Sam'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Ethan'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Johnson'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Bob'); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------+ | Name | +---------+ | John | | Sam | | Mike | | Ethan | | Johnson | | Bob | +---------+ 6 rows in set (0.00 sec)
Following is the query to fetch multiple values beginning with “Joh” −
mysql> select *from( select Name as myValue from DemoTable union select Name from DemoTable )tbl where myValue like 'Joh%';
This will produce the following output −
+---------+ | myValue | +---------+ | John | | Johnson | +---------+ 2 rows in set (0.00 sec)
- Related Articles
- How to fetch fields with multiple values set using MySQL LIKE?
- Use LIKE % to fetch multiple values in a single MySQL query
- Can we fetch multiple values with MySQL WHERE Clause?
- Can we use MySQL GROUP BY clause with multiple columns like MySQL DISTINCT clause is used?
- How to use user variables in MySQL LIKE clause?
- How to use MySQL DISTINCT clause on multiple columns?
- MySQL query to fetch multiple least values?
- Update with multiple values in MySQL WHERE clause
- How to use MySQL VIEW with WHERE clause?
- What MySQL returns when we use DISTINCT clause with the column having multiple NULL values?
- How to use the ‘except’ clause with multiple exceptions in Python?
- How to use MySQL Date functions with WHERE clause?
- MySQL REGEXP to fetch string + number records beginning with specific numbers?
- SHOW TABLE statement with multiple LIKE values in MySQL?
- What is the alternative of BETWEEN clause to fetch values between a range in MySQL?

Advertisements