- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL query to search within the last 5 characters in a column?
Let us first create a table −
mysql> create table DemoTable -> ( -> EmployeeName varchar(100) -> ); Query OK, 0 rows affected (0.81 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Adam Smith'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Carol Taylor'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('David Miller'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Chris Evan'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+--------------+ | EmployeeName | +--------------+ | Adam Smith | | Carol Taylor | | David Miller | | Chris Evan | +--------------+ 4 rows in set (0.00 sec)
Following is the query to search within the last 5 characters of a column −
mysql> select *from DemoTable where Right(EmployeeName, InStr(EmployeeName, ' ' )) LIKE 'Mille%';
Output
This will produce the following output −
+--------------+ | EmployeeName | +--------------+ | David Miller | +--------------+ 1 row in set (0.00 sec)
- Related Articles
- MySQL query to remove everything except the last 7 characters in column record
- MySQL query to conduct a basic search for a specific last name in a column
- Search for specific characters within a string with MySQL?
- Search for a string within text column in MySQL?
- Strip last two characters of a column in MySQL?
- MySQL query to split a column after specific characters?
- MySQL query to search between comma separated values within one field?
- MySQL Query to remove all characters after last comma in string?
- MySQL query to get a substring from a string except the last three characters?
- MySQL query to get substrings (only the last three characters) from strings?
- MySQL query to remove special characters from column values?
- MySQL query to replace special characters from column value
- MySQL query to retrieve only the column values with special characters?
- MySQL query to replace a string after the last / in a column with directory links?
- A single MySQL query to search multiple words from different column values

Advertisements