So I've been looking through the internet the last hour, reading and looking for the definitive answer to this simple question.
What is the default JOIN in MySQL?
SELECT * FROM t1 JOIN t2
Is that the same as
SELECT * FROM t1, t2 OR SELECT * FROM t1 INNER JOIN t2
Also a related question, when you use "WHERE" clauses, is it the same as JOIN or INNER JOIN ?
Right now I'm thinking a stand-alone JOIN is identical to using commas and WHERE clauses.
INNER is the default; LEFT, RIGHT, and FULL imply an outer join. The join condition is specified in the ON or USING clause, or implicitly by the word NATURAL. The join condition determines which rows from the two source tables are considered to "match", as explained in detail below.
The simplest and most common form of a join is the SQL inner join the default of the SQL join types used in most database management systems. It's the default SQL join you get when you use the join keyword by itself. The result of the SQL inner join includes rows from both the tables where the join conditions are met.
JOIN defaults to INNER JOIN behaviour.
In MySQL, JOIN , CROSS JOIN , and INNER JOIN are syntactic equivalents (they can replace each other). In standard SQL, they are not equivalent. INNER JOIN is used with an ON clause, CROSS JOIN is used otherwise.
In MySQL writing JOIN
unqualified implies INNER JOIN
. In other words the INNER
in INNER JOIN
is optional. INNER
and CROSS
are synonyms in MySQL. For clarity I write JOIN
or INNER JOIN
if I have a join condition and CROSS JOIN
if I don't have a condition.
The allowed syntax for joins is described in the documentation.
Right now I'm thinking a stand-alone JOIN is nothing more than (identical to) using commas and WHERE clauses.
The effect is the same, but the history behind them is different. The comma syntax is from the ANSI-89 standard. However there are a number of problems with this syntax so in the ANSI-92 standard the JOIN keyword was introduced.
I would strongly recommend that you always use JOIN syntax rather than the comma.
T1 JOIN T2 ON ...
is more readable than T1, T2 WHERE ...
.These are all equivalent, and also equal to, CROSS JOIN
.
There are some differences between using comma and [INNER | CROSS] JOIN
syntax, which might be important when joining more tables. Pretty much all you need to know is described here in the MySQL JOIN
documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With