SQL WHERE

Keeps only the rows that match a condition — the single most-used clause in SQL.

What & Why

WHERE filters rows before they're returned — the database checks every row's values against your condition, and keeps only the ones where it's true.

See How It Works

BUSINESS QUESTION

Keep only campaigns with spend more than 50,000.

idnamechannelspendstart_dateend_datestatustarget_segment
1Spring Launchgoogle_ads55000.002024-01-152024-03-31activesmb
2Retention Webinaremail45000.002024-02-102024-04-15activeenterprise
3Finance Retargetinglinkedin50000.002024-03-122024-05-31activeenterprise
4Enterprise Searchgoogle_ads60000.002024-04-012024-06-30activeenterprise
Watch where check each rowRow 1 of 4
-- checking Spring Launch: 55000 > 50000?TRUE — kept
namespend
Spring Launch55000
Retention Webinar45000
Finance Retargeting50000
Enterprise Search60000

spend > 50000 is true for Spring Launch.

EXAMPLE QUERY
SELECT name, spend
FROM marketing.campaigns
WHERE spend > 50000;
Now You Try

Practice this concept

Marketing wants active campaigns only. Return campaign name, channel, and status.

Available schema
marketing

Prefix tables with marketing.table_name.

namechannelstatus
marketing.campaigns
ColumnType
idinteger
nametext
channeltext
spendnumeric
start_datedate
end_datedate
statustext
target_segmenttext
legacy_idtext
query.sql
Beginner business practice

Sign up free to try it on a real business scenario