SQL NOT BETWEEN

Matches everything outside the range — both endpoints excluded from the match this time.

What & Why

NOT BETWEEN keeps only values falling outside the range — including values exactly equal to either endpoint are now excluded from matching, since those are exactly what BETWEEN included.

See How It Works

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
EXAMPLE QUERY
SELECT name, spend FROM marketing.campaigns
WHERE spend NOT BETWEEN 45000 AND 55000;
RESULT
namespend
Enterprise Search60000.00

Only Enterprise Search (60000) falls outside 45000-55000 — everyone else from the BETWEEN example is now excluded.

Now You Try

Practice this concept

SaaS finance wants invoices with amounts outside the normal $120 through $200 band.

Available schema
saas

Prefix tables with saas.table_name.

idaccount_idamountstatus
saas.invoices
ColumnType
idinteger
account_idinteger
amountnumeric
statustext
due_datedate
paid_attimestamp with time zone
internal_invoice_batchtext
query.sql
Beginner business practice

Sign up free to try it on a real business scenario