我正在尝试使用INNER JOIN函数从多个表中提取特定信息,并且我认为我的语法有问题-想到太多或太少()。社区对此有何看法?
SELECT Employee.EmployeeID
,Service.HoursWorked
FROM (
Equipment INNER JOIN (Equipment Repair)
ON Equipment.EquipmentID = Equipment Repair.RepairID
)
INNER JOIN (
(
(
Service INNER JOIN EMPLOYEE
ON Service.ProductID = EMPLOYEE.EmployeeID
) INNER JOIN (
OWNER INNER JOIN Property
ON OWNER.OwnerID = Property.OwnerID
)
INNER JOIN SubProperty
ON Property.PropertyID = SubProperty.PropertyID
)
ON Service.PropertyID = Subproperty.PropertyID
)
INNER JOIN TrainingCourse
ON EMPLOYEE.EmployeeID = TrainingCourse.EmployeeID
ON Equipment.EquipmentID = TrainingCourse.EquipmentID ORDER BY Employee.EmployeeID
答案 0 :(得分:-1)
您的查询正在尝试将多个表连接在一起,但是您可能也在尝试使用括号吗?这些没有您可能期望的效果。
没有(显然吗?)假括号,我将理解该查询的含义:
SELECT
Employee.EmployeeID
,Service.HoursWorked
FROM Equipment
INNER JOIN (Equipment Repair)
ON Equipment.EquipmentID = Equipment Repair.RepairID
INNER JOIN Service
INNER JOIN EMPLOYEE
ON Service.ProductID = EMPLOYEE.EmployeeID
INNER JOIN OWNER
INNER JOIN Property
ON OWNER.OwnerID = Property.OwnerID
INNER JOIN SubProperty
ON Property.PropertyID = SubProperty.PropertyID
ON Service.PropertyID = Subproperty.PropertyID
INNER JOIN TrainingCourse
ON EMPLOYEE.EmployeeID = TrainingCourse.EmployeeID
ON Equipment.EquipmentID = TrainingCourse.EquipmentID
ORDER BY Employee.EmployeeID
但这仍然存在错误,因为许多联接缺少联接条件,而有些联接具有多个联接条件。
相反,您需要考虑要表达的projection operation。结果集中应该出现哪些列,哪些表(告诉您要联接的表),以及在什么条件下表Foo中的行应出现在总结果集中(告诉您该表的联接条件)