
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
Find Records with a Specific Last Digit in MySQL
For this, use the RIGHT() method to fetch records with a specific last digit. Let us first create a table −
mysql> create table DemoTable823(Value varchar(100)); Query OK, 0 rows affected (0.54 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable823 values('9847826'); Query OK, 1 row affected (0.52 sec) mysql> insert into DemoTable823 values('84747464'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable823 values('9899889883'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable823 values('123456'); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable823;
This will produce the following output −
+------------+ | Value | +------------+ | 9847826 | | 84747464 | | 9899889883 | | 123456 | +------------+ 4 rows in set (0.00 sec)
Following is the query to find records with a specific last digit −
mysql> select *from DemoTable823 where right(Value,1)='6';
This will produce the following output −
+---------+ | Value | +---------+ | 9847826 | | 123456 | +---------+ 2 rows in set (0.00 sec)
Advertisements