
- 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 some of the values from the table
Use NOT IN() to exclude some of the values from the table.
Let us first create a table −
mysql> create table DemoTable791 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(100) ); Query OK, 0 rows affected (0.61 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable791(FirstName) values('Chris'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable791(FirstName) values('Robert'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable791(FirstName) values('David'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable791(FirstName) values('Mike'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable791(FirstName) values('Bob'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable791(FirstName) values('Carol'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable791(FirstName) values('Adam'); Query OK, 1 row affected (0.09 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable791;
This will produce the following output -
+----+-----------+ | Id | FirstName | +----+-----------+ | 1 | Chris | | 2 | Robert | | 3 | David | | 4 | Mike | | 5 | Bob | | 6 | Carol | | 7 | Adam | +----+-----------+ 7 rows in set (0.00 sec)
Following is the query to exclude some of the values from the table using NOT IN() in MySQL −
mysql> select *from DemoTable791 where Id NOT IN(4,5,6);
This will produce the following output -
+----+-----------+ | Id | FirstName | +----+-----------+ | 1 | Chris | | 2 | Robert | | 3 | David | | 7 | Adam | +----+-----------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL query to replace only the NULL values from the table?
- MySQL query to count all the column values from two columns and exclude NULL values in the total count?
- MySQL query to exclude values having specific last 3 digits
- MongoDB collection query to exclude some fields in find()?
- MySQL query for INSERT INTO using values from another table?
- Insert values from the first table to the second table using two SELECT statements in a single MySQL query
- MySQL query to get first two highest column values from a table?
- JavaScript - Exclude some values in average calculation
- How to exclude a specific row from a table in MySQL?
- Query the database for the values not in the MySQL table?
- MySQL query to match any of the two strings from column values
- Exclude some ID records from a list and display rest in MySQL
- How can I create a stored procedure to select values on the basis of some conditions from a MySQL table?
- MySQL query to count number of duplicate values in a table column
- MySQL query to select average from distinct column of table?

Advertisements