AND ,OR ,NOT Operators in MySQL (original) (raw)

Last Updated : 27 Mar, 2026

The AND, OR, and NOT operators in MySQL are logical operators used to filter records based on one or more conditions. They are mainly used with the WHERE clause to control how data is retrieved from a table.

First, we will create a demo table on which the logical operators will be used:

Screenshot-2026-03-27-105042

students Table

AND Operator

The AND operator is used to combine multiple conditions in a query and returns records only when all conditions are TRUE.

**Syntax:

SELECT * FROM table_name WHERE condition1 AND condition2;

**Example: Find students who belong to CSE branch and are from CALIFORNIA:

SELECT * FROM students WHERE branch = 'CSE' AND state = 'CALIFORNIA';

**Output:

Screenshot-2026-03-27-104446

OR Operator

The OR operator is used to combine multiple conditions and returns records when at least one condition is TRUE.

**Syntax:

SELECT * FROM table_name WHERE condition1 OR condition2;

**Example: Find students who belong to CSE or ECE branch:

SELECT * FROM students WHERE branch = 'CSE' OR branch = 'ECE';

**Output:

Screenshot-2026-03-27-104837

NOT Operator

The NOT operator is used to negate a condition and returns records where the condition is FALSE.

**Syntax:

SELECT * FROM table_name WHERE NOT condition;

**Example: Find students who are not from TEXAS:

SELECT *
FROM students
WHERE NOT state = 'TEXAS';

**Output:

Screenshot-2026-03-27-105354