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.

Intermediate business practice

Sign up free to try it on a real business scenario