
- 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 restrict MySQL `LIKE` operator to begin with specific characters?
Let us first create a table −
mysql> create table DemoTable ( FirstName varchar(40) ); Query OK, 0 rows affected (0.52 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('Adam'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Sam'); Query OK, 1 row affected (0.09 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-----------+ |FirstName | +-----------+ | John | | Adam | | David | | Mike | | Sam | +-----------+ 5 rows in set (0.00 sec)
Following is the query to restrict `LIKE` operator to begin with specific characters −
mysql> select *from DemoTable where FirstName LIKE 'D%' or FirstName LIKE 'S%';
This will produce the following output −
+-----------+ | FirstName | +-----------+ | David | | Sam | +-----------+ 2 rows in set (0.00 sec)
- Related Articles
- Display specific table names with MySQL LIKE Operator
- How to select records that begin with a specific value in MySQL?
- MySQL query to count records that begin with specific letters
- What are the different wildcard characters that can be used with MySQL LIKE operator?
- MySQL query to select a specific string with special characters
- How to use MySQL SOUNDEX() function with LIKE operator to retrieve the records from table?
- MySQL query to find same value on multiple fields with LIKE operator?
- How can we restrict access to methods with specific HTTP verbs in C# ASP.NET\nWebAPI?
- How Are MySQL INSTR() and LIKE operator similar?
- Search for specific characters within a string with MySQL?
- How do I begin auto increment from a specific point in MySQL?
- MySQL query to split a column after specific characters?
- How LIKE operator works with comparison operators for matching specific kinds of patterns of a string?
- What are the different wildcard characters which can be used with NOT LIKE operator?
- How to get the maximum value from a column with alphanumeric strings beginning with specific characters in MYSQL?

Advertisements