MySQL + SQL · Lesson 47
Comparison and Logical Operators in SQL
Comparison Operators
| Operator | Example |
|---|---|
| = | marks = 100 |
| <> / != | city != 'Delhi' |
| > >= | age >= 18 |
| < <= | fee < 5000 |
Logical Operators
-- AND: both must be true
SELECT * FROM students WHERE class='10' AND marks>=60;
-- OR: at least one true
SELECT * FROM students WHERE city='Delhi' OR city='Agra';
-- NOT: reverse
SELECT * FROM students WHERE NOT class='10';
Summary
- Comparison: =, !=, >, <, >=, <=.
- Logical: AND (both), OR (either), NOT (reverse).