
- 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
Display all records except one in MySQL
You can use IN() to display all records except one in MySQL. Let us first create a table −
mysql> create table DemoTable ( Id int, FirstName varchar(20) ); Query OK, 0 rows affected (0.57 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(100,'Larry'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable values(10,'Chris'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(110,'Robert'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(90,'David'); Query OK, 1 row affected (0.20 sec)
Following is the query to display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------+-----------+ | Id | FirstName | +------+-----------+ | 100 | Larry | | 10 | Chris | | 110 | Robert | | 90 | David | +------+-----------+ 4 rows in set (0.00 sec)
Here is the query to display all records except one in MySQL −
mysql> select *from DemoTable where Id IN(110,90,100);
This will produce the following output −
+------+-----------+ | Id | FirstName | +------+-----------+ | 100 | Larry | | 110 | Robert | | 90 | David | +------+-----------+ 3 rows in set (0.00 sec)
- Related Articles
- Display NULL and NOT NULL records except a single specific value in MySQL
- Display all records ignoring the current date record in MySQL
- Display records ignoring NULL in MySQL
- Find and display duplicate records in MySQL?
- Display records by grouping dates in MySQL
- How to select all the records except a row with certain id from a MySQL table?
- How to display all the MySQL tables in one line?
- How to remove Duplicate Records except a single record in MySQL?
- How to select all rows from a table except the last one in MySQL?
- Select all rows except from today in MySQL?
- Move all files except one on Linux
- Ordering alphabetically in MySQL except for one entry?
- Display records after a particular date in MySQL
- How to display coming Sunday's date for all the date records in MySQL?
- MongoDB query to display all the fields value, except _id

Advertisements