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

**Code:** `cartesian` · **Category:** SQL · **Seen on:** SQL, MySQL, PostgreSQL

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/sql/accidental-cartesian-product-cross-join)
