How to use mysql JOIN without ON condition?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
A MySQL JOIN without an ON clause is valid SQL, but it does not behave like a typical relational join. In most cases it produces a Cartesian product, meaning every row on the left is paired with every row on the right. This can be useful in controlled scenarios, but dangerous if used accidentally.
What JOIN Without ON Actually Means
When you omit ON, you are usually asking for full pairing between tables, equivalent to CROSS JOIN.
If products has 100 rows and regions has 5 rows, the result has 500 rows.
Some developers also write comma joins, which have similar behavior before filtering:
This older syntax is legal, but explicit CROSS JOIN is clearer and easier to review.
Use Cases Where Cartesian Join Is Intentional
There are legitimate cases for this pattern. One common example is generating all combinations of dimensions for reporting.
Output gives every day and shift pair, which is useful for building schedule templates.
Another use case is creating test datasets by multiplying small seed tables.
This quickly generates values from 0 to 99 without procedural loops.
Add Filtering with WHERE if Needed
A join without ON can still be restricted later in WHERE. This is functionally similar to an inner join, but many teams prefer explicit ON for readability.
The query works, but equivalent explicit syntax is easier to maintain:
Use WHERE filtering mainly when you intentionally start from a Cartesian set and then apply additional logical constraints.
Prefer Explicit Join Semantics in Production
If the goal is relational matching, write the condition in ON even when WHERE would produce the same rows. This makes intent obvious during review and reduces accidental query changes.
This style separates relationship logic from row filtering logic, which improves maintainability as queries evolve.
Performance and Safety Considerations
Cartesian joins can explode row counts and consume memory, temp space, and execution time. Use EXPLAIN before running large queries.
If row estimates are high, add limits for inspection:
This helps verify structure before running full scans in production data.
Common Pitfalls
A common mistake is forgetting the join condition and unintentionally returning millions of rows. If results look far larger than expected, verify whether an ON clause is missing.
Another issue is using comma join syntax in modern codebases. It still works, but reviewers can miss implicit Cartesian behavior more easily than with explicit CROSS JOIN.
Teams also place relationship predicates only in WHERE and later add additional filters that change semantics by accident. Prefer explicit ON for relational joins and reserve no-ON syntax for intentional Cartesian combinations.
Summary
- A
JOINwithoutONusually means Cartesian product behavior. - Use explicit
CROSS JOINwhen full combinations are intentional. - Add
WHEREfilters carefully if you start from a Cartesian set. - Use explicit
ONclauses for relational matching in production queries. - Run
EXPLAINto check row growth and query cost before large runs.
Related reading
- How to use MySQLdb with Python and Django in OSX 10.6?
- How to use MySQLdb with Python and Django in OSX 10.6?
- how to use pymysql executemany insert many rows and get the ids of each rows
- How to use Spring Boot with MySQL database and JPA?
- How to use Spring managed Hibernate interceptors in Spring Boot?
- How to use the dumped data by mongodump?
- How to use the Kafka Connect JDBC to source PostgreSQL with multiple schemas that contain tables with the same name?
- how to use views in code first entity framework

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.