
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 Select Column Values Ending with Certain Character
Let us first create a table −
mysql> create table DemoTable ( Number int ); Query OK, 0 rows affected (0.80 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(189); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(178); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(876); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(784); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(988); Query OK, 1 row affected (0.23 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------+ | Number | +--------+ | 189 | | 178 | | 876 | | 784 | | 988 | +--------+ 5 rows in set (0.00 sec)
Following is the query to select column values ending with a specific character/number. Here, we are focusing on values ending with number 8 −
mysql> select *from DemoTable where Number LIKE '%8';
This will produce the following output −
+--------+ | Number | +--------+ | 178 | | 988 | +--------+ 2 rows in set (0.00 sec)
Advertisements