
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
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)
Advertisements