Learn SQL/Intermediate/Joins/SQL Non-Equi JOIN

SQL Non-Equi JOIN

Any join whose condition uses something other than = — the general family the JOINs with Comparison Operators lesson introduced, now named explicitly.

What & Why

"Non-equi join" is simply the name for any join whose ON condition doesn't use plain equality — >, <, >=, <=, or != all qualify. It's a category label for the comparison-operator technique from two lessons ago, not a different SQL keyword.

See How It Works

BUSINESS QUESTION

SaaS finance matches each account to invoices whose amount is at least that account's MRR.

idnameplanmrrcreated_atchurned_atcountryemployee_countindustry
1Acme Labsgrowth240.002024-01-08 10:00:00+00NULLUS45software
2Northstar Costarter90.002024-02-12 09:30:00+002024-05-18 12:00:00+00CA18services
3Atlas Worksscale480.002024-03-04 15:10:00+00NULLGB120manufacturing
4Bright Pathgrowth180.002024-04-19 11:45:00+00NULLUS62education
idaccount_idamountstatusdue_datepaid_at
101240.00paid2024-02-012024-01-29 13:00:00+00
111260.00paid2024-03-012024-02-28 16:30:00+00
12290.00overdue2024-03-15NULL
133480.00open2024-04-01NULL
EXAMPLE QUERY
SELECT
  a.name,
  a.mrr,
  i.id AS invoice_id,
  i.amount
FROM saas.accounts a
JOIN saas.invoices i
  ON i.account_id = a.id
 AND i.amount >= a.mrr
ORDER BY a.name, invoice_id;
RESULT — exact output from the displayed Queryflo rows
namemrrinvoice_idamount
Acme Labs240.0010240.00
Acme Labs240.0011260.00
Atlas Works480.0013480.00
Northstar Co90.001290.00

The account key matches first; the inequality then keeps invoices meeting MRR.

Now You Try

Practice this concept

SaaS finance wants invoices whose amount is at least the MRR of their own account.

Available schema
saas

Prefix tables with saas.table_name.

account_namemrrinvoice_idamount
saas.accounts
ColumnType
idinteger
nametext
plantext
mrrnumeric
created_attimestamp with time zone
churned_attimestamp with time zone
countrytext
employee_countinteger
industrytext
customer_segment_v2text
saas.invoices
ColumnType
idinteger
account_idinteger
amountnumeric
statustext
due_datedate
paid_attimestamp with time zone
internal_invoice_batchtext
query.sql
Intermediate business practice

Sign up free to try it on a real business scenario