Labs ICT
โญ Pro Login

WHERE Clause

SELECT without WHERE is like buying a car without steering โ€” technically it moves, but you cannot control where it goes. WHERE is how you filter data and get only the rows you actually care about.

Basic Filtering

Let us find all students who are older than 21:

SELECT * FROM students WHERE age > 21;

Comparison Operators

SQL gives you all the standard comparison operators:

  • = โ€” equal to
  • <> or != โ€” not equal to
  • > โ€” greater than
  • < โ€” less than
  • >= โ€” greater than or equal
  • <= โ€” less than or equal
-- Students who are exactly 22
SELECT * FROM students WHERE age = 22;

-- Students who are NOT from Kano
SELECT * FROM students WHERE city != 'Kano';

-- Students with score 80 or higher
SELECT * FROM students WHERE score >= 80;

Notice that text values go in single quotes 'Kano'. Numbers do not need quotes. This is one of those things beginners forget all the time โ€” I definitely did when I started.

WHERE with Text

When filtering text, remember that SQL is case-sensitive depending on the database system. SQLite is case-sensitive for exact matches:

-- This might not find anything if the stored value is 'kano'
SELECT * FROM students WHERE city = 'kano';

-- Use LIKE for case-insensitive (we will cover this more later)
SELECT * FROM students WHERE city LIKE 'Kano';

๐Ÿงช Quick Quiz

Which clause is used to filter rows in SQL?