SQL AND ,OR, NOT Operators
SQL AND, OR, NOT OPERATOR:- The WHERE clause can be combined with AND, OR, NOT Operators.




These operators are used to filter records based on more than one condition.
SQL AND OPERATOR:- The AND operator displays a record if all the conditions separated by AND are TRUE.
SYNTAX:-
SELECT column1 ,column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ... ;
EXAMPLE:-
Consider the CUSTOMERS table having the following records:-
AND Example:-
The following SQL statement selects all fields from "CUSTOMERS" where Address is "Delhi" AND Age is "23":-
SELECT CustomerID , Name ,Address , Age ,Salary
FROM CUSTOMERS
WHERE Address = 'Delhi' AND Age = 23 ;
OUTPUT:-
SQL OR OPERATOR:- The SQL OR Operator is used to create a SQL statement where records are returned when any one of the conditions met.
Syntax:-
SELECT column1 ,column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ... ;
EXAMPLE:-
The following SQL statement selects all fields from "CUSTOMERS" where Address is "Delhi" OR Salary is "20000":-
SELECT CustomerID , Name ,Address , Age ,Salary
FROM CUSTOMERS
WHERE Address = 'Delhi' OR Salary = 20000 ;
OUTPUT:-
SQL NOT OPERATOR:- The NOT operator displays a record if the condition is NOT TRUE.
Syntax:-
SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;
EXAMPLE:-
The following SQL statement selects all fields from "CUSTOMERS" where Address is NOT "Delhi ":-
SELECT CustomerID , Name ,Address , Age ,Salary
FROM CUSTOMERS
WHERE NOT Address ='Delhi' ;
OUTPUT:-
Comments
Post a Comment