How to Use Multiple Joins in SQL: Best Example

Here is the best example of writing an SQL query with multiple JOIN statements.

Photo by Evie Shaffer on Pexels.com

SQL Query with multiple Join Statements

SELECT m.f1, o.f1, s.f1
FROM Material m
LEFT OUTER JOIN Catalog c
ON m.MaterialName = c.MaterialName
AND m.EffectiveDate = c.EffectiveDate
AND c.MaterialType = 'X1' AND (c.MaterialName Like 'xyz%' OR
c.MaterialName Like '%abc')
LEFT OUTER JOIN OrderHeader o
ON o.OrderList = m.OrderList
AND o.OrderDate BETWEEN '01-01-2004' AND '12-31-2004'
LEFT OUTER JOIN Ship s
ON o.OrderList = s.OrderList
AND s.ShipVendorID in ('UPS','YF')

Related

Discover more from Srinimf

Subscribe now to keep reading and get access to the full archive.

Continue reading