Code / SQL with Data / Unit 2: Filtering with WHERE

AND, OR, IN and BETWEEN AND, OR, IN और BETWEEN

Lesson 4 of 13 · about 14 minutes · Combine conditions and test lists and ranges.

⚡ 0 XP

Step 1 of 2

Two conditions at once

if ?true ✓else ✗

Join conditions with AND and OR:

  • AND: both must be true — team = 'Delhi' AND role = 'Batter'
  • OR: at least one must be true — team = 'Delhi' OR team = 'Mumbai'

When you mix them, use brackets so SQL knows what you mean: WHERE role = 'Bowler' AND (team = 'Delhi' OR team = 'Mumbai').

Example
SELECT name, team
FROM players
WHERE role = 'Batter'
  AND runs > 1500;

🎯 Challenge: All-rounders who take wickets +15 XP

Show name, team and wickets of players whose role is All-rounder and who took 30 or more wickets.

Try twice to unlock the solution (0/2)

query.sqlCtrl ⏎
Tables (practice database)
Results

Press Run to see your query’s rows here.

Checklist

Press Run to check your code.

  • Your rows match the expected answer
  • Uses AND
Lesson notes (text version)

1. Two conditions at once

Join conditions with AND and OR:

  • AND: both must be true — team = 'Delhi' AND role = 'Batter'
  • OR: at least one must be true — team = 'Delhi' OR team = 'Mumbai'

When you mix them, use brackets so SQL knows what you mean: WHERE role = 'Bowler' AND (team = 'Delhi' OR team = 'Mumbai').

                SELECT name, team
FROM players
WHERE role = 'Batter'
  AND runs > 1500;
              

Challenge: All-rounders who take wickets

Show name, team and wickets of players whose role is All-rounder and who took 30 or more wickets.

2. Lists and ranges: IN, BETWEEN

Two handy shortcuts:

  • team IN ('Delhi', 'Kolkata') is the same as team = 'Delhi' OR team = 'Kolkata'
  • matches BETWEEN 30 AND 38 is the same as matches >= 30 AND matches <= 38 — both ends are included

They make long conditions short and easy to read.

                SELECT name, team
FROM players
WHERE team IN ('Chennai', 'Mumbai');
              

Challenge: Delhi and Kolkata regulars

Show name, team and matches of players whose team is Delhi or Kolkata (use IN) and who played between 30 and 38 matches, both included (use BETWEEN).

Search by task, format or tool name.