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

WHERE: only the rows you want WHERE: सिर्फ़ चाहिए वाली पंक्तियाँ

Lesson 3 of 13 · about 12 minutes · Equals, not-equals and comparing numbers.

⚡ 0 XP

Step 1 of 2

Matching text

if ?true ✓else ✗

WHERE keeps only the rows for which a condition is true. It comes after FROM:

SELECT name FROM players WHERE team = 'Delhi';

  • Text goes in single quotes: 'Delhi'
  • Text must match exactly: 'delhi' is not 'Delhi'
  • <> means “not equal”: WHERE role <> 'Bowler'

Think of WHERE as a sieve (छलनी): every row is tested, only the true ones pass through.

Example
SELECT name, role
FROM players
WHERE team = 'Delhi';

🎯 Challenge: The Mumbai squad +10 XP

Show name and role of the players whose team is Mumbai.

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 WHERE
Lesson notes (text version)

1. Matching text

WHERE keeps only the rows for which a condition is true. It comes after FROM:

SELECT name FROM players WHERE team = 'Delhi';

  • Text goes in single quotes: 'Delhi'
  • Text must match exactly: 'delhi' is not 'Delhi'
  • <> means “not equal”: WHERE role <> 'Bowler'

Think of WHERE as a sieve (छलनी): every row is tested, only the true ones pass through.

                SELECT name, role
FROM players
WHERE team = 'Delhi';
              

Challenge: The Mumbai squad

Show name and role of the players whose team is Mumbai.

2. Comparing numbers

For numbers you can use >, <, >= (at least) and <= (at most). Numbers need no quotes:

SELECT name, wickets FROM players WHERE wickets >= 50;

Careful with words: “more than 1000” is > 1000 (1000 itself is not included), while “1000 or more” is >= 1000.

                SELECT name, wickets
FROM players
WHERE wickets >= 50;
              

Challenge: The 1000-run club

Show name and runs of every player who scored more than 1000 runs.

Search by task, format or tool name.