SQL – And , Or , Not Operator
Table Of Contents:
- What Is And , Or , Not Operator.
- Syntax Of And , Or , Not Operator.
- Examples Of And , Or , Not Operator.
(1) What Is And , Or , Not Operator
- And , Or, Not Operator can be used with the “Where” clause.
- The
ANDoperator displays a record if all the conditions separated byANDare TRUE. - The
ORoperator displays a record if any of the conditions separated byORis TRUE. - The
NOToperator displays a record if the condition(s) is NOT TRUE.
(2) Syntax Of And , Or , Not Operator
AND Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...; OR Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...; NOT Syntax
SELECT column1, column2, ...
FROM table_name
WHERE NOT condition; (3) Examples Of And , Or , Not Operator
Demo Data:
Example-1: AND Operator
SELECT * FROM Customers
WHERE Country='Germany' AND City='Berlin';
Example-2: OR Operator
SELECT * FROM Customers
WHERE City='Berlin' OR City='München';
Example-3: NOT Operator
SELECT * FROM Customers
WHERE NOT Country='Germany';
Example-4: Combining AND, OR and NOT
SELECT * FROM Customers
WHERE Country='Germany' AND (City='Berlin' OR City='München');
Example-5: Combining AND, OR and NOT
SELECT * FROM Customers
WHERE NOT Country='Germany' AND NOT Country='USA';

