Algorithm for writing joins in SQL
Date: 25 Jun 2003 23:39:41 -0700
Message-ID: <c97b9fa.0306252239.3bcdcc8c_at_posting.google.com>
Hi, I have a reporting application that needs to dynamically generate the sql query based on conditions & sorting. The underlying database is a simple star structure with inner joins between tables only.
I need to be able to create the nested inner join syntax as is done in SQL server and MS Access query builders.
Can anyone suggest an algorithm or some key words I can search for in set theory or something?
I have the tables and joins
Order{..Product_Key, Category_Key, Employee_Key}
- Product{Product_Key..}
- Category{Category_Key..}
- Employee{Employee_Key..}
Inventory{.Product_Key, Category_Key, Supplier_Key}
- Product{Product_Key..}
- Category{Category_Key..}
- Supplier{Supplier_Key..}
Where product and category are common to order and inventory.
Which should translate into...
FROM Product INNER JOIN (Supplier INNER JOIN (Employee INNER JOIN
((Category INNER JOIN Inventory ON Category.Category_Key =
Inventory.Category_Key) INNER JOIN Order ON Category.Category_Key =
Order.Category_Key) ON Employee.Employee_Key = Order.Employee_Key) ON
Supplier.Supplier_Key = Inventory.Supplier_Key) ON
(Product.Product_Key = Order.Product_Key) AND (Product.Product_Key =
Inventory.Product_Key)
Thanks
Sello
Received on Thu Jun 26 2003 - 08:39:41 CEST