SQL NOT Operator - The Coding Shala

Home >> Learn SQL >> SQL NOT Operator

SQL NOT Operator

The SQL 'NOT' Operator displays records if the condition is not true.
SQL NOT Operator - The Coding Shala

SQL NOT Operator Syntax

The basic syntax of SQL NOT Operator is as follows - 

SELECT column1, column2, ...  
 FROM table_name  
 WHERE NOT condition;

SQL NOT Operator Examples 

The following 'emp' table will be used for the examples - 

Id     Name     Age     Address     Salary  
 1     Akshay     22     Pune        40000  
 2     Mohit      21     Delhi       42000  
 3     Akash      21     Delhi       45000  
 4     Nikhil     24     Mumbai      50000  
 5     Smith      24     Pune        50000  
 6     Akshay     22     Pune        50000  
 7     Nikhil     24     Mumbai      43000 

The following query will return records if Name is not Akshay - 

 SQL >> select * from emp   
       where NOT Name = 'Akshay';  
 
Output >>   
 Id     Name     Age     Address     Salary  
 2     Mohit      21     Delhi      42000  
 3     Akash      21     Delhi      45000  
 4     Nikhil     24     Mumbai     50000  
 5     Smith      24     Pune       50000  
 7     Nikhil     24     Mumbai     43000 


Other Posts You May Like
Prev<< SQL OR Operator                                                                   NEXT >>SQL Wildcard Operator
Please leave a comment below if you like this post or found some error, it will help me to improve my content.

Comments

Popular Posts from this Blog

Shell Script to find sum, product and average of given numbers - The Coding Shala

Shell Script to Create a Simple Calculator - The Coding Shala

Add two numbers in Scala - The Coding Shala

New Year Chaos Solution - The Coding Shala

Richest Customer Wealth LeetCode Solution - The Coding Shala