vendredi 30 janvier 2015

SQL Multiple JOINS Interpretation order [on hold]


I have a big problem of using multiple joins in one SQL Statement.


For example i have 10 Tables which they are tbl1,tbl2, tbl3,..,tbl10.


I would like to select some columns from each table from tbl1 till tbl10.


Relations for example are like following:


but if i used JOINS i in between i don't know how to use Left,Right,etc in the SQL Statement from Priority aspect. I mean is it with Parenthesis organized or like what?


Example for the SQL: enter image description here


And my Query is as following



SELECT T1.col1, T2.col2, T3.col3, T4.col1 AS Expr1
FROM T1 INNER JOIN T1_T2 ON T1.id = T1_T2.T1_FK
INNER JOIN T2 ON T1_T2.T2_FK = T2.id
LEFT JOIN T2_T3 ON T2.id = T2_T3.T2_FK
INNER JOIN T3 ON T2_T3.T3_FK = T3.id
LEFT JOIN T3_T4 ON T3.id = T3_T4.T3_FK
INNER JOIN T4 ON T3_T4.T4_FK = T4.id


So how does SQL Server interprate the JOINs ? can one represent it like Execution Priorities with Paranthesis?


I mean: ( (T1 INNER Join T1_T2) INNER JOIN T2 ) LEFT JOIN T2_T3) ?


Thanks alot for feedbacks




Edited for More Explanation:





Aucun commentaire:

Enregistrer un commentaire