Merged into mysql5

I saw people write the following query

SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name

      

written like this:

SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON table_name2.column_name =table_name1.column_name

      

does it really matter?

+2


source to share


3 answers


Not under normal circumstances, no. Imagine there might be a fairly complex query, much more complex than your examples, where the join optimizer is so overwhelmed that it might make a difference, but even if it is possible, you have to work quite hard.

You can write both of them as USING (column_name)

by the way. :)



I would also recommend that you familiarize yourself with the DIY analysis of such problems EXPLAIN

.

p>
+4


source


There is no difference.

table_name1.column_name=table_name2.column_name

      

and



table_name2.column_name=table_name1.column_name

      

have the same meaning.

The "left" side of the join refers to tables, not comparisons - I guess that was your implicit question?

+7


source


This is probably a matter of personal taste; I happen to write unions like your second example, but I can't say that I am 100% in agreement with that.

Also, in The Bad Old Days, when query optimizers weren't as smart as they are now, you might find that reordering the operands in a union expression or clause WHERE

can make a big difference; that is, the optimizer will use the index if the operands are ordered in one direction, but not in the opposite direction.

I think I have Oracle 7 flash memory. Got to lie down ...

0


source







All Articles