No difference, algebraically the queries are identical and will have the same performance.
Your query below is written in the pattern ANSI 89
SELECT * FROM clientes c, enderecos e WHERE c.id = e.id_cliente;
The same query written in the pattern ANSI 92
SELECT * FROM clientes c JOIN enderecos e ON c.id = e.id_cliente;
Personally I prefer to use the pattern ANSI 92
, for a few reasons:
- More readable, with the separate union criteria of the clause
WHERE
, because it is not known at first if conditions in the clase WHERE
are filters or junctions.
- Less likely to lose union criteria, at the first consultation if we do not specify the criterion in the clause
WHERE
the result will be the Cartesian product among the customer tables,
- Evolution, if the ANSI 92 standard specifies specific junction operators, why not use them?
- Flexibility, an addition to the clause
WHERE
which has an effect of INNER JOIN
and then needs to be changed to OUTER
can be much more complicated
2 Considerations: First, don’t use only Join, use Ner Join, it is more visible. Second, always use the shape with Inner Join, because in addition to being more legible, you may need to put a left Join later and it’s easier and faster to understand. About your question there is no difference.
– Tiedt Tech
related
– rray
Except for the @Rlon.Tiedt comment, no response was satisfactory regarding the "best organization" part. A multi-table query using only WHERE is almost impossible to read.
– utluiz
Whereas I prefer to use only
JOIN
instead ofINNER JOIN
. That’s because I organize my code with indentation to the right of the first word of each line.– Tiago César Oliveira
@Marlon.Tiedt I didn’t understand what you said about
left joins
– Gabe
@Gabe, imagine an SQL with 10 tables. Everything works 100%. Then they put a new table,
CLIENTE_TITULOS
. If you do Inner Join, with the client table and there are no titles, the client will not appear. Now imagine you have an SQL in the patternclientes c, enderecos e left join CLIENTE_TITULOS
. looks like it got out of pattern. Looks more beautifulclientes c inner join enderecos e left join CLIENTE_TITULOS
. Of course in the SQL above I omitted the fields for lack of space. Tendeu?– Tiedt Tech
@Ah, got it. You guys say use always
inner joins
instead of "multiple"wheres
makes it more "simple" (cute :D) to insert aright|left join
then if you need to. It makes sense.– Gabe
This even...plus more elegant, it is easier to maintain
– Tiedt Tech