
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 Exclude Values with Specific Last 3 Digits
For this, use NOT IN. Let us first create a table −
mysql> create table DemoTable(Value int); Query OK, 0 rows affected (0.71 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(1234); Query OK, 1 row affected (0.54 sec) mysql> insert into DemoTable values(2345); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(7896); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(4321); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------+ | Value | +-------+ | 1234 | | 2345 | | 7896 | | 4321 | +-------+ 4 rows in set (0.00 sec)
Following is the query to exclude values having specific last 3 digits −
mysql> select *from DemoTable where right(Value,3) NOT IN('234','321');
This will produce the following output −
+-------+ | Value | +-------+ | 2345 | | 7896 | +-------+ 2 rows in set (0.00 sec)
Advertisements