How does SQL process "wrapped joins"?

Viewed 41

I'm going through some older code, and one query is laid out in the following manner:

FROM (A INNER JOIN (B LEFT JOIN C ON B.ID2 = C.ID2) ON A.ID1= B.ID1)

I'm confused as to how this would actually be processed? What's the difference between the above and below?

FROM A
INNER JOIN B ON A.ID1 = B.ID1
LEFT JOIN C on B.ID2 = C.ID2
1 Answers

The first code uses subquery. I used the Northwind data base to test this if both codes produce the same results.

I first used the first query:

Select *
From(Categories c JOIN (Products p Left Join Suppliers s on p.SupplierID=s.SupplierID) on c.CategoryID=p.CategoryID)

Then I used the following query:

Select * 
From Categories c
Join Products p on c.CategoryID=p.CategoryID
Left Join Suppliers s on p.SupplierID=s.SupplierID

It seems they produce the exact same result. Furthermore, in both queries I changed Inner Join with Left Join and and Left Join with Inner join. And I tested it and they seem to give same results. So I think they are the same.

Related