All,
I’m reviewing some basic MySQL JOIN tutorials. Jeff Atwood gives an example on his blog that goes like this:
SELECT * FROM TableA
LEFT OUTER JOIN TableB
ON TableA.name = TableB.name
It seems to me that the query doesn’t need – from a semantic standpoint – the TableB mention on the second line. Do I understand that correctly? It seems to me that all the info is already available in the 3rd line.
I’m not trying to stir any type of trouble about the efficiency of the SQL language, I just want to understand whether this mention of TableB brings any new info, in this context or in others.
It doesn’t bring new info, but it does bring precision and the ability for you to alias the table:
Note that in this formulation I can both explicitly ask for the data from a and figure out the join more easily in line 3. However, the compiler wouldn’t have non-arbitrary guidance as to where to get that information of what table to use unless I explicitly declare it. Consider if this was the way SQL worked:
Am I saying that the tableB is aliased ‘b’, or TableB.name is aliased ‘b’? It’s just confusing; better to be explicit and authoritative.