E0021 missing-join-condition
Tables in FROM with no condition linking them.
| Code | Name | Category | Default |
|---|---|---|---|
E0021 | missing-join-condition | suspicious | warn |
What it reports
A table in a comma-separated FROM list that nothing links with the other tables: no WHERE condition references it together with another table. Every row is combined with every row of the others (a cross join), which multiplies the result and is usually a forgotten join condition.
Example
SELECT u.name, o.total FROM users u, orders o;
warning[E0021]: No condition links 'o' with the other tables: every row is joined with every row (cross join)
--> q.sql:1:38
|
1 | SELECT u.name, o.total FROM users u, orders o;
| ^^^^^^
= help: Add a join condition for 'o' to WHERE, or write CROSS JOIN if every combination is intended
Fixed:
SELECT u.name, o.total FROM users u, orders o WHERE o.user_id = u.id;
Notes
Explicit joins (CROSS JOIN, JOIN ... ON) are never reported. To keep deliberate cross joins quiet, nothing is reported when:
- a
WHEREcondition filters one of the tables on its own (WHERE t.name = 'rust': every row combined with the chosen ones), - the other item is a CTE, a subquery or a table function (it may return a single row), or refers to an earlier table (
LATERAL,unnest(u.tags), BigQueryu.tags), - the statement has template tags (they may add conditions), or a condition uses a column sqlsift can't attribute to one table.
A condition that references several tables links all of them, also inside OR or a subquery.
Configuring
# sqlsift.toml
[rules]
missing-join-condition = "error" # or "off"
Or for a single line: -- sqlsift:disable E0021. The examples use the schema on the Rules page.