

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- Display specific table names with MySQL LIKE Operator
- MySQL query to count records that begin with specific letters
- How to select records that begin with a specific value in MySQL?
- 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 Are MySQL INSTR() and LIKE operator similar?
- What are the different wildcard characters which can be used with NOT LIKE operator?
- How do I begin auto increment from a specific point in MySQL?
- How can we restrict access to methods with specific HTTP verbs in C# ASP.NET WebAPI?
- Search for specific characters within a string with MySQL?
- How LIKE operator works with comparison operators for matching specific kinds of patterns of a string?
- MySQL query to split a column after specific characters?
- What is the significant difference between MySQL LIKE and equal to (=) operator?
Advertisements