4130
MariaDBERRORNotableHIGH confidence

Wrong usage of outer join in query

Production Risk

Low — The query fails or returns incorrect results.

Why it happens
  1. 1An OUTER JOIN has a WHERE condition on the outer table that effectively converts it to an INNER JOIN.
  2. 2The join syntax is malformed according to MySQL parsing rules.

Fix

Move outer-table conditions to the ON clause

Move outer-table conditions to the ON clause
SELECT * FROM a LEFT JOIN b ON a.id = b.a_id AND b.status = 1;

Why this works

Conditions on the outer table in a LEFT JOIN belong in the ON clause, not the WHERE clause.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 4130 ER_WRONG_OUTER_JOIN2

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MariaDB errors