Quick Syntax
SELECT column1, column2
FROM table_name
WHERE condition;
Alright, here’s the vibe: You’ve got a table full of stuff — names, cities, orders, whatever. But you don’t want everything. You just want some rows. Maybe people over 30, or users from a certain city.
That’s when you bring in WHERE
. It’s like telling SQL:
“Show me only the rows where this thing is true.”
Let me walk you through it like we’re at the same desk, coffee in hand.
Say You Have This Table Called clients
id | name | age | city | subscription |
---|---|---|---|---|
1 | Renzo Blip | 41 | Driftwood | free |
2 | Moxi Tern | 24 | Cloudhill | pro |
3 | Jara Nix | Dustvale | basic | |
4 | Kito Grail | 31 | Cloudhill | free |
5 | Fenn Rask | 27 | — | trial |
6 | Lume Paddo | 45 | Driftwood | pro |
No famous names, no perfect data — just a funky little table you need to work with.
Suppose You Want People in Cloudhill
SELECT name, city
FROM clients
WHERE city = 'Cloudhill';
Output:
Moxi Tern Cloudhill
Kito Grail Cloudhill
Now You Only Want Clients Over 30
SELECT name, age
FROM clients
WHERE age > 30;
Output:
Renzo Blip 41
Kito Grail 31
Lume Paddo 45
Let’s Say You’re Hunting Free Plan Users
SELECT name, subscription
FROM clients
WHERE subscription = 'free';
Output:
Renzo Blip free
Kito Grail free
Missing Info? Use IS NULL
SELECT name, age
FROM clients
WHERE age IS NULL;
Output:
Jara Nix NULL
Note: Use IS NULL
— not = NULL
. That won’t work.
Wanna Combine Conditions? Easy.
Now let’s say you want people who:
- Live in Driftwood
- AND are on a
pro
plan
SELECT name, city, subscription
FROM clients
WHERE city = 'Driftwood' AND subscription = 'pro';
Output:
Lume Paddo Driftwood pro
Recap – Here’s What You Learned
WHERE
helps you filter rows- Use operators like
=
,>
,<
,!=
- Use
IS NULL
for missing values - Combine conditions with
AND
/OR
- It’s like spreadsheet filters — but with superpowers
Now that you know how WHERE
works, next let’s check out DISTINCT
.
It helps you get results with no repeats — like a list of all different cities, not every single row.
See how it works here.