I have a SQL script with nested inner joins in the FROM clause:
SELECT
...
FROM
(t1
INNER JOIN
(t2
INNER JOIN
((t3
INNER JOIN
t4
ON
t3.ContractID = t4.ContractID AND
t3.Line = t4.Line)
INNER JOIN
t5
ON
t3.TaskID = t5.TaskID AND
t3.ContractID = t5.ContractID)
ON
t2.TaskID = t5.TaskID)
ON
t1.PaymentID = t2.PaymentID AND
t1.ContractID = t2.ContractID)
INNER JOIN
t6
ON
t1.Email = t6.Email
WHERE
(t3.ContractID = 'abc123')
AND
(t2.PaymentID = '12')
I was wondering how to simplify and format nested joins like the one above?
If I remember correctly, all kinds of joins are associative and commutative, and can these properties be used to simplify nested joins?
Thanks.