SQL IN

Check membership in a list of values — cleaner than chaining several OR conditions.

What & Why

IN checks whether a value matches any item in a list. channel IN ('google_ads', 'linkedin') means exactly the same thing as channel = 'google_ads' OR channel = 'linkedin', just shorter and more readable once the list grows past two or three values.

See How It Works

BUSINESS QUESTION

Campaigns in google_ads or linkedin.

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
Check each campaign against the channel listRow 1 of 4
-- checking Spring Launch: 'google_ads' IN ('google_ads', 'linkedin')TRUE — kept
namechannel
Spring Launchgoogle_ads
Retention Webinaremail
Finance Retargetinglinkedin
Enterprise Searchgoogle_ads

channel IN ('google_ads', 'linkedin') is true for Spring Launch.

EXAMPLE QUERY
SELECT name FROM marketing.campaigns
WHERE channel IN ('google_ads', 'linkedin');
Now You Try

Practice this concept

Marketing wants campaigns from email, SEO, or referral channels.

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