以下是我在下面尝试查询的问题。
对于每个订单,列出订单号,订单日期,部件号,部件描述和项目 构成订单的每个部分的类
数据库有一个Order_Line表,由order_num,Part_num,Num ordered和quoted_price组成。它还有一个order_num,order_date和Customer_num的订单表。此查询使用的第三个表是具有Part_num,description,On_Hand,Class,Warehouse和Price的part表。看来我必须加入所有三个表。这是我试过的查询。
Select Orders.Order_Num, Order_Date, Part.Part_Num , Description, Class
From Orders, Customer, Part
Where Orders.Order_Num = Order_Line.Order_Num
And Order_Line.Part_Num = Part.Part_Num
答案 0 :(得分:0)
Select * --<-- use two part names here
From Customer
INNER JOIN Orders ON Customer.CustomerID = Orders.CustomerID --<-- Only guessing
INNER JOIN Order_Line ON Orders.Order_Num = Order_Line.Order_Num
INNER JOIN Part ON Order_Line.Part_Num = Part.Part_Num
您还没有提到如何将查询中的订单加入到客户表中,这为您提供了两个表的笛卡尔积。
答案 1 :(得分:0)
你错过了一张桌子,似乎在你的名单中有一张额外的桌子:
您可能正在尝试这样做:
Select Orders.Order_Num, Order_Date, Part.Part_Num , Description, Class
From Orders
inner join part on
Order_Line.Part_Num = Part.Part_Num
inner join OrderLine on
Orders.Order_Num = Order_Line.Order_Num
- 无法判断哪些列'客户'表可以加入....