Module 02 · lesson 3

AND, OR, NOT: complex conditions

A buyer is looking for electronics cheaper than $100 to stock up the budget segment. That's already two conditions at once.

Combining conditions

Logical operators combine several conditions:

  • AND — true when both conditions hold;
  • OR — true when at least one does;
  • NOT — negation of a condition.

For example, books cheaper than $30:

SELECT name, category, price
FROM products
WHERE category = 'Books' AND price < 30;

A row passes only if both parts are true. As for precedence: AND is "stronger" than OR, so when you mix them — add parentheses to avoid a surprise (there's a separate lesson on this).

AND OR NOT A B обидві умовиboth conditions las dos condiciones A B хоча б однаat least one al menos una A поза умовоюoutside the condition fuera de la condición A = category 'Books' · B = price < $30

Your turn

The buyer needs electronics cheaper than $100. Output the name, category, and price of such products.

Summary

  • AND — both conditions;
  • OR — at least one;
  • NOT — negation.