What is NOT Logical Operator in SQL Server - SQL Server / TSQL Tutorial Part 121

Logical Operators are used to test some conditions. If the condition is true, the row will be selected for output.

What is NOT Logical Operator : 

NOT logical operator is used when we want to return the row if specified condition is false.

Scenario :
Let's say that you have dbo.Customer table and you would like to return all the records but where FName is not equal to 'Raza'.

Create table dbo.Customer
 (Id int,
  FName VARCHAR(50),
  LName VARCHAR(50),
  CountryShortName CHAR(2))
GO
insert into dbo.Customer
Values (
1,'Raza','M','PK'),
(2,'Rita','John','US'),
(3,'Sukhi','Singh',Null),
(4,'James','Smith','CA'),
(5,'Robert','Ladson','US'),
(6,'Alice','John','US'),
(7,'Raza','M','US')



We can use NOT Logical Operation to get our required results.

Select * From dbo.Customer
where NOT FName='Raza'

How to use Logical Not Operator in SQL Server - SQL Server / TSQL Tutorial


Noticed that it returned all the rows for which the condition is false.

No comments:

Post a Comment