cartesian SQL Origin: Data OSI layer 7 · Application Last updated 18 Nov 2026

Query returns far too many rows: accidental Cartesian product (missing JOIN condition)

Two tables were joined without a condition, so every row of one pairs with every row of the other.

Exact message you may see Cartesian productaccidental cross joincross join missing ON clausequery returns millions of rows after joinmissing join condition duplicates rows
Seen on: SQL MySQL PostgreSQL

Meaning

A missing ON, a comma join with the WHERE condition forgotten, or a condition that always matches multiplies rows (1000 x 1000 = 1,000,000). Always join with explicit ON, check row counts with COUNT(*) and review the execution plan for "nested loop" without a predicate.

Common causes

  • Comma join FROM a, b without a WHERE link
  • Missing or wrong ON condition
  • Join on a non-unique column
  • Using CROSS JOIN by mistake
  • Join condition on the wrong alias

⚡ Quick fix

  1. Use explicit JOIN ... ON with the key columns
  2. Compare COUNT(*) before and after the join
  3. Inspect the plan for a Cartesian/cross join

Detailed fix by platform

SQL

  1. SELECT o.id, c.name FROM orders o JOIN customers c ON c.id = o.customer_id;

How to diagnose

  1. ON — Present?
  2. Row count — Exploded?
  3. Plan — Cartesian?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

= NULL — WHERE col = NULL returns no rows (use IS NULL) (SQL)= NULL000606 — Snowflake: No active warehouse selected in the current session (SQL)000606209 — SQL Server Msg 209: Ambiguous column name (SQL)2094104 — SQL Server Msg 4104: The multi-part identifier could not be bound (SQL)410457014 — ERROR: canceling statement due to statement timeout (PostgreSQL)57014CASE — CASE expression returns mixed types: conversion failed / types cannot be matched (SQL)CASECOMMIT — Changes disappear: transaction never committed (autocommit off, missing COMMIT) (SQL)COMMITCOUNT — COUNT(column) ignores NULLs: counts differ from COUNT(*) (SQL)COUNTcartesian

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.