SQL Fundamentals

Lesson 2 of 6

Filtering with WHERE

SELECT name, xp
FROM students
WHERE xp >= 100;

SELECT name
FROM students
WHERE name LIKE 'A%';

Comparisons and patterns

  • WHERE filters rows before they're returned, only rows where the condition is true make it into the result.
  • LIKE 'A%' matches names starting with A, % is a wildcard for "anything, any length".
  • Combine conditions with AND / OR, and control the result order with ORDER BY:
SELECT name, xp
FROM students
WHERE xp >= 50 AND name != 'Ada'
ORDER BY xp DESC;

ORDER BY xp DESC sorts highest-XP first, drop DESC (or use ASC) to sort lowest first.

📝 WHERE Clause Quiz

Passing score: 70%
  1. 1.Which keyword matches a text pattern like a prefix or suffix?

  2. 2.To sort query results from highest to lowest, you add ORDER BY column ____.

  3. 3.The WHERE clause filters rows before they are included in the result set.