Logical operators
- SQL course
- Beginner
- Lesson 32/115
- 4 min
Learn AND, OR, NOT logical operators.
Comparison operators
=, <>, <, >, <=, >= are comparison operators. They compare a column with a constant in a condition.
SELECT name FROM products WHERE price >= 50;This query products with price 50 or more.
name is selected from products. WHERE keeps only the rows where price >= 50 holds.
Comparison operators — details
For not-equal use <> or !=. ANSI SQL prefers <>. Text comparison uses the same operators.
Practice Comparison operators
Select names from products where price is greater than or equal to 50.
Starter code
-- comparison
SELECT name
FROM products
WHERESample solution
SELECT name
FROM products
WHERE price >= 50Expected output
name Çanta Masa
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Logical operators: match the terms
| Term | Meaning |
|---|---|
= |
equal |
<> |
not equal |
>= |
greater or equal |
<= |
less or equal |
2 Greater or equal
SELECT name FROM products WHERE price ____ 50;
SELECT name FROM products WHERE price >= 50;
Explanation: >= means greater than or equal; 50 is included too.
3 Which writes not-equal?
- ==
- !=
- =/
- <> Correct answer
Explanation: <> means not equal.