CodeBlanks Logo Icon CodeBlanks

Logical operators

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

query.sql
-- comparison
SELECT name
FROM products
WHERE

Sample solution

query.sql
SELECT name
FROM products
WHERE price >= 50

Expected 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

Question
SELECT name FROM products WHERE price ____ 50;
Answer
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.

All lessons in Beginner