If I'm selecting equal fields from two tables, does it matter which table to SELECT
from and which to JOIN
from?
I guess I'm really interested in how best to join tables. Are there guidelines for which to SELECT FROM
and which to JOIN
, or when it doesn't matter?
I'm working on a query that joins about 5 tables and not sure if it matters which I pull from and which I join. Currently I'm using FROM
the table my WHERE
clause pulls from. I assume this is the correct way, but any explanations or guidelines would be great!
Same applies for LEFT JOIN
, as the feedback I see is that the default INNER JOIN
does not matter.
For example
SELECT
a.field1,
a.field2,
a.field3,
b.field1,
b.field2
choice 1:
FROM
a
JOIN
b ON a.field1 = b.field1
WHERE
a.field1 = 'abc'
Choice 2:
FROM
b
JOIN
a ON b.field1 = a.field1
WHERE
a.field1 = 'abc'