Italian Trulli

SQL AND OR NOT Operator with Example

Test Tribe
.

AND, OR, NOT Operator in SQL 

AND Operator In SQL

In SQL AND operator is used to display only those records where both the conditions, condition-1 and condition-2 evaluate to True.

In other words, we say that " SQL AND operator is a conditional Operator used to display a record if all the conditions separated by AND are TRUE.

Syntax of AND Operator

The basic syntax of the AND operator is given below

 

SELECT column1, column2, ... FROM table_name WHERE condition1 AND condition2 AND condition3 ...;

Example of AND Operator 
An example of AND Operator is given below.

SELECT * FROM Employee WHERE Country='India' AND City='Uttar Pradesh';


The Above SQL statement selects all fields from the "Employee" Table where the country name is "India" AND the city name  is "Uttar Pradesh"

OR Operator In SQL

In SQL OR operator is used to display the records where either one of the conditions condition1 or condition2 evaluates to True. That is, either condition1 is True or condition2 is True.

In other words, we say that " SQL OR operator is a conditional Operator is used to display a record if any of the conditions separated by OR is TRUE.

Syntax of OR Operator

The basic syntax of the OR operator is given below 


SELECT column1, column2, ... FROM table_name WHERE condition1 OR condition2 OR condition3 ...;

Example of OR Operator 
An example of OR Operator is given below.

SELECT * FROM Employee WHERE Country='India' OR City='Uttar Pradesh';

The Above SQL statement selects all fields from the "Employee" Table where the country name  is "India" Or the city name  is "Uttar Pradesh"


NOT Operator In SQL

In SQL NOT Operator is used to display a record if the condition is not true.

Syntax of NOT Operator
The basic syntax of the NOT operator is given below.


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


Example of NOT Operator 
An example of NOT Operator is given below.

SELECT * FROM Employee WHERE NOT Country='India';

The Above SQL statement selects all fields from "Employee" where the country is NOT "India":

SQL AND OR NOT Operator with Example 

Post a Comment

0 Comments