⚡ 180+ new openings posted today

SQL AND,OR and NOT Operators

The Where clause can be combined with AND, OR, and NOT Operators.

The SQL AND & OR Operators are used to combine multiple conditions to narrow data in an SQL statement. These two operators are called the conjunctive operators.

The AND operator displays a record if all the condition separated by AND is TRUE.

The OR operator displays a record if any conditions separated by OR is TRUE.

The NOT operator displays a record if the conditions is not TRUE.

1. AND Operator

The AND operator returns rows only if all conditions are true.

Syntax:

SELECT column_name
FROM table_name
WHERE condition1 AND condition2;

Example:

SELECT *
FROM Employees
WHERE Department = 'Finance' AND Salary > 50000;

Result: Displays employees who work in the Finance department and earn more than 50,000.

2. OR Operator

The OR operator returns rows if at least one condition is true.

Syntax:

SELECT column_name
FROM table_name
WHERE condition1 OR condition2;

Example:

SELECT *
FROM Employees
WHERE Department = 'IT' OR Department = 'Finance';

Result: Displays employees who belong to either the IT department or the Finance department.

3. NOT Operator

The NOT operator reverses a condition. It returns rows where the condition is false.

Syntax:

SELECT column_name
FROM table_name
WHERE NOT condition;

Example:

SELECT *
FROM Employees
WHERE NOT Department = 'Finance';

Result: Displays employees who are not in the Finance department.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top