I don't have a problem with the nested JOINs - it would have helped if you had used [CODE] tags to preserve the formatting, but your original indentation is visible by pressing REPLY to your post.Having said that I don't do it that way, and Yeah! wars have been fought over less!...FROM TableA INNER JOIN ( TableB INNER JOIN TableB_Child1 ON B1_Col = B_Col ) ON B_Col = A_Col
has the benefit that INNER JOIN can easily be changed to an Outer Join whilst preserving the localised hierarchy relationship of TableB and TableB_Child1Dunno how often that happens in real life though!FWIW I definitely preferSELECT T1.Data1FROM Table1 AS T1 INNER JOIN Table2 AS T2 ON T2.Key=T1.Key INNER JOIN Table3 AS T3 ON T3.Key=T2.Key
toSELECT T1.Data1FROM Table1 T1 INNER JOIN Table2 T2 ON T1.Key=T2.Key INNER JOIN Table3 T3 ON T2.Key=T3.Key
note that I have added "AS" to reduce the risk of an accidental space separating two words, and turned round your ON so that the Target columns are on the left. Mostly JOIN'd tables are joined on their PK, so this provides easy checking, on left hand side, that all PK columns have been satisfied. Also where there are multiple key columns it stops the criticality wandering off the right side of the screen, and makes tests against static values obvious:SELECT T1.Data1FROM Table1 AS T1 JOIN Table2 AS T2 ON T2.PkKey1 = T1.Col1 AND T2.PkKey2 = T1.ColN AND T2.IsActive = 1
We don't bother with INNER but we do use OUTER in a LEFT join - to make it more obvious that it is "different"Our style has evolved to fight bugs that creep in during code maintenance, and suits us - in the sense of helping DEVs spot goofy things more often, and generate fewer bugsFor example, we doSELECT [TheName] = SomeColumnOrExpression
rather thanSELECT SomeColumnOrExpression AS [TheName]
because expressions are variable width and push [TheName] to the right and make it less easy to spot and associate with the column.Same withWHERE ... Col1 = Col2 AND Col3 = Col4 OR ...
andWHERE ... Col1 = Col2 AND Col3 = Col4 OR ... ...
we do the second for the same reason (yeah, I know, that example needs some parenthesis! but it highlights the fact that it makes that issue more likely to be spotted than if it is off the right end of the screen)We don't doIF ( ... lots of stuff ) {...}either, we line the brackets up so we can see what goes with whatIF ( ... lots of stuff ){...}similarly with BEGIN / END in SQLBut ask two programmers about coding style and you'll get at least three answers !