
- 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
How do I exclude a specific record in MySQL?
You can exclude a specific record in SQL using not equal to operator(!=). Let us first create a table−
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName varchar(20), ClientCountryName varchar(10) ); Query OK, 0 rows affected (0.64 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable(ClientName,ClientCountryName) values('John','US'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(ClientName,ClientCountryName) values('David','AUS'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable(ClientName,ClientCountryName) values('Mike','UK'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+------------+-------------------+ | Id | ClientName | ClientCountryName | +----+------------+-------------------+ | 1 | John | US | | 2 | David | AUS | | 3 | Mike | UK | +----+------------+-------------------+ 3 rows in set (0.00 sec)
Following is the query to exclude a specific record in MySQL i.e. we are excluding records with ClientName David' or ClientCountryName ='AUS'−
mysql> select *from DemoTable where ClientName!='David' or ClientCountryName!='AUS';
This will produce the following output−
+----+------------+-------------------+ | Id | ClientName | ClientCountryName | +----+------------+-------------------+ | 1 | John | US | | 3 | Mike | UK | +----+------------+-------------------+ 2 rows in set (0.00 sec)
- Related Articles
- How to exclude a specific row from a table in MySQL?
- Display only a specific duplicate record in MySQL
- How do I select data that does not have a null record in MySQL?
- How to select record except the lower value record against a specific value in MySQL?
- How do I begin auto increment from a specific point in MySQL?
- Write a single MySQL query to exclude a record and display NULL value
- Implement specific record ordering with MySQL
- How to get a specific column record from SELECT query in MySQL?
- Replace a specific duplicate record with a new value in MySQL
- How do I add a field to existing record in MongoDB?
- Delete a specific record on the basis of EmployeeId in MySQL
- How to select a specific record from MySQL if date is in VARCHAR format?
- MySQL query to exclude values having specific last 3 digits
- How to find a specific record from a list of values with semicolon in MySQL?
- MySQL CONCAT a specific column value with the corresponding record

Advertisements