SQL & Databases·Querying data

Filtering and sorting

Combine conditions, match patterns and order results predictably.

Beginner 13 min read Lesson 2 of 480 Challenge included
What you will be able to do
  • Combine AND and OR
  • Use LIKE and IN
  • Handle NULL correctly

Filters are where SQL becomes precise. Group conditions carefully — AND binds more tightly than OR, so use parentheses when mixing them.

filter.sqlSQL
SELECT title, minutes, level
FROM lessons
WHERE (level = 'Beginner' OR level = 'Intermediate')
  AND minutes <= 15
  AND title LIKE '%form%'
ORDER BY minutes ASC, title ASC;
OperatorMeaning
=Exact match
<>Not equal
LIKEPattern match; % is any length, _ is one character
INMatches any value in a list
BETWEENInclusive range
IS NULLTests for a missing value
Your turn

Find short lessons

Easy

Return titles of lessons under 12 minutes, ordered by minutes ascending.

SQL · starter
SELECT title, minutes FROM lessons
Check your understanding before moving on.
Knowledge checkQuestion 1

How do you test for a missing value?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Database design basics
Lesson 2 of 480 · 0% of course