Combining conditions
Ask a more specific question
Lesson 4 of 20 · 7 min · Module 2: Ask precise questions
Useful questions often have more than one condition. SQL lets you combine them while keeping your query readable.
Start this lesson →Free. No installation: you write and run the code in your browser, and it is checked automatically.
By the end, you’ll be able to…
- Combine conditions with AND and OR
- Make grouping explicit with parentheses
- Sort filtered results
The idea
Use AND when both conditions must be true. Use OR when either condition is enough. Parentheses make your intended grouping explicit.
SELECT name FROM learners
WHERE language = 'Python' AND xp > 200;
01Describe the intended logic
A learner must use either JavaScript or Python, and must also have enough XP. The parentheses group the two language possibilities before applying the shared XP requirement.
02Avoid relying on a reader remembering precedence
AND binds more tightly than OR. Explicit parentheses make the query’s intention visible and avoid accidentally accepting one language without the XP rule.
Your turn
name and xp for learners studying JavaScript or Python who have at least 150 XP. Sort by XP, highest first.What the checks look for
- Returns Sam and Mia in descending XP order
Take this with you
Group conditions the same way you would explain the rule in words.