I've got the following request :
select *
from tbA A, tbB B, tbC C, tbD D
where
A.ID=B.ID and B.ID2= C.ID2 and A.ID=D.ID and C.ID3=D.ID3 and B.ID4=D.ID4
and
A.Foo='Foo'
I've heard several times that this join syntax is depreciated, and that I should use the 'JOIN' keyword instead.
How do I do that in such a complicated join (multiple tables joined on multiple columns belonging to different tables)? Do you think this best practice still applies here ?
I find join syntax much easier to understand
Now you can clearly see how data are joined together and that it is not a very complicated join altogether.
BTW, the database design in your example strongly smells of lacking normalization. Usually you should have either one table joining to many (a join b on a.bid = b.bid join c on a.cid= c.cid) or a chain (a join b on a.bid = b.bid join c on b.cid = c.cid).
EDIT. Added optional keyword INNER which does not change result, but makes it more clear.
Though I'm having a hard time imagining any need for that. Bare to give an example, or eh more descriptive table names?
JOIN
syntax is more legible (though I personally preferWHERE
syntax in simple cases), and, which is more important, can handleINNER
andOUTER
joins in more clear way.WHERE
is not deprecated and will probably never be.It's deprecated only in a sense that different
OUTER JOIN
workarounds (like(*)
and(+)
) are deprecated.There is nothing you cannot do with
JOIN
that you can do withWHERE
, but not vise versa.It's a matter of taste, but I like the JOIN keyword better. It makes the logic clearer and is more consistent with the LEFT OUTER JOIN syntax that goes with it. Note that you can also use INNER JOIN which is synonymous with JOIN.
The syntax is
b can be a join itself. For inner joins it doesn't matter, but for outer you can control the order of the joins like this:
Here a is left-joined to the inner join between d and c.
Here is your query: