Home >Database >Mysql Tutorial >Can MySQL JOIN Queries Work Without an ON Condition?
Joining Tables in MySQL Without ON Condition
In MySQL, it is possible to perform join queries without specifying an ON condition. This differs from the ANSI SQL standard and other database systems.
Cross Join
When using JOIN or INNER JOIN without an ON clause, the result is a cross join. A cross join produces a Cartesian product, creating every possible combination of rows from the joined tables. For example, if Table A has three rows ('a', 'b', 'c') and Table B has four rows (1, 2, 3, 4), the cross join would result in 12 rows.
To perform a cross join explicitly, it is recommended to use the CROSS JOIN syntax:
FROM A CROSS JOIN B
This is preferable to using:
FROM A, B
which can also result in a cross join but can be confusing.
Outer Joins
The ON clause is required for RIGHT OUTER JOIN and LEFT OUTER JOIN. Therefore, the discussion of JOIN without ON does not apply to these types of joins.
The above is the detailed content of Can MySQL JOIN Queries Work Without an ON Condition?. For more information, please follow other related articles on the PHP Chinese website!