
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL query to exclude values having 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)
- Related Articles
- MySQL query to exclude some of the values from the table
- MySQL query to update every alternative row string having same values?
- Get the sum of last 3 digits from all the values in a column with MySQL
- MySQL query to count all the column values from two columns and exclude NULL values in the total count?
- How do I exclude a specific record in MySQL?
- How to exclude a specific row from a table in MySQL?
- MySQL query to display only the column values with corresponding column having whitespace
- MySQL query to select the values having multiple occurrence and display their count
- MySQL query to conduct a basic search for a specific last name in a column
- MySQL query to fetch specific records matched from an array (comma separated values)
- MySQL query for grouping and summing the values based on specific records
- Get multiple count in a single MySQL query for specific column values
- How to display records having sum between a specific range using GROUP BY, HAVING and ORDER BY in a single MySQL query?
- Query MySQL table and fetch rows posted before the last 3 days?
- Write a single MySQL query to exclude a record and display NULL value

Advertisements