Sikau

Databases and SQL · Day 2 · about 30 min

Filtering with WHERE

Comparisons, AND / OR, IN, LIKE and NULL.

Only what you need

Databases hold millions of rows; you rarely want them all. WHERE keeps only rows that match a condition — and the database does the filtering, which is far faster than loading everything into your app.

Conditions

SELECT name, price FROM dishes WHERE price < 200;

SELECT name FROM dishes WHERE veg = true AND category = 'Starter';

SELECT name FROM dishes WHERE category IN ('Drink', 'Snack');

SELECT name FROM dishes WHERE name ILIKE '%momo%';

SELECT name FROM dishes WHERE spice_level IS NULL;

The rest of this lesson

  • AND, OR and parenthesesexplain
  • NULL means unknownexplain
  • Does it match?predict
  • Equals NULLpredict
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 17 lessons of Databases and SQL