

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
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 Questions & Answers
- How to exclude a specific row from a table in MySQL?
- How do I select data that does not have a null record in MySQL?
- Display only a specific duplicate record 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
- How do I add a field to existing record in MongoDB?
- Implement specific record ordering with MySQL
- How to select record except the lower value record against a specific value in 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 insert a record from one Mongo database into another?
- How do I remove a MySQL database?
- MySQL query to exclude values having specific last 3 digits
- Java regex to exclude a specific String constant
- How do I create a view in MySQL?
Advertisements