CodeBlanks Logo Icon CodeBlanks

Comparison operators

Learn =, <>, !=, <, >, <=, >= comparisons.

Logical operators

AND, OR, NOT logical operators combine conditions. AND requires both, OR needs at least one.

SELECT name FROM products
WHERE price > 10 AND stock > 0;

This query products with price over 10 and stock over 0.

name is selected from products. WHERE keeps only the rows where price > 10 AND stock > 0 holds.

Logical operators — details

NOT negates a condition: WHERE NOT city = 'Istanbul'. Parentheses make precedence explicit.

Practice Logical operators

Select names from products where price > 10 AND stock is NOT > 0.

Starter code

query.sql
-- logical query
SELECT name
FROM products
WHERE

Sample solution

query.sql
SELECT name
FROM products
WHERE price > 10 AND NOT stock > 0

Expected output

name
Kalem

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Logical not

Question
SELECT name FROM products
WHERE ____ (price < 5);
Answer
SELECT name FROM products
WHERE NOT (price < 5);

Explanation: NOT negates a condition; NOT (price < 5) returns prices of 5 or more.

2 What does NOT do?

  • Removes the condition
  • Repeats the condition
  • Negates the condition Correct answer
  • Strengthens the condition

Explanation: NOT negates the condition.

3 Comparison operators: match the terms

Term Meaning
AND both
OR at least one
NOT negation
parentheses precedence

All lessons in Beginner