If you have several tables joined together, but only one of them has a limiting condition, is it better to just lay it all out like this:
... or is it better to use a subquery on the table with the condition?
... or does it not matter because the server will know what to do automatically?
Code:
SELECT
a.Field1
,b.Field2
,c.Field3
,d.Field4
,e.Field5
FROM
ATable a
INNER JOIN BTable b WITH (NOLOCK)
ON a.ID = b.aID
INNER JOIN CTable c WITH (NOLOCK)
ON a.ID = c.aID
INNER JOIN DTable d WITH (NOLOCK)
ON c.ID = d.cID
INNER JOIN ETable e WITH (NOLOCK)
ON d.ID = e.dID
WHERE
b.Foo = 'Bar'
... or is it better to use a subquery on the table with the condition?
Code:
SELECT
a.Field1
,b.Field2
,c.Field3
,d.Field4
,e.Field5
FROM
ATable a
INNER JOIN (SELECT
sub.aID
FROM
BTable sub
WHERE
sub.Foo = 'Bar'
) as b
ON a.ID = b.aID
INNER JOIN CTable c WITH (NOLOCK)
ON a.ID = c.aID
INNER JOIN DTable d WITH (NOLOCK)
ON c.ID = d.cID
INNER JOIN ETable e WITH (NOLOCK)
ON d.ID = e.dID
... or does it not matter because the server will know what to do automatically?