简体   繁体   English

Ms Access SQL中的多权限联接问题,返回语法错误

[英]Multiple Right Join Issue in Ms Access SQL, Returns SYNTAX ERROR

I'm having some issues with (I think) the SQL. 我在使用SQL时遇到一些问题。 I'm no expert here but have read that multiple joins need to be wrapped in parenthesis, however I just cannot make this work. 我在这里不是专家,但已经读到,多个连接需要用括号括起来,但是我无法完成这项工作。

Maybe this isn't even the issue, this is most likely down to me not fully understanding exactly what is going on here! 也许这甚至不是问题,这最有可能归因于我对这里到底发生了什么并不完全了解! If someone could tell me what stupid thing I've done here that'd be great! 如果有人可以告诉我我在这里做了什么愚蠢的事情,那将是很棒的!

When I open the form where the listbox is referencing this query ComponentFinalHomeListboxQuery I get: 当我打开列表框引用此查询ComponentFinalHomeListboxQuery的表单时,我得到:

"Syntax error (missing operator) in query expression '[DatabaseComponentID] ='. “查询表达式'[DatabaseComponentID] ='中的语法错误(缺少运算符)。

The list still populates but displays the error before each record appears in the listbox. 列表仍在填充,但在每个记录出现在列表框中之前显示错误。

Changing the join between ComponentMasterCostQuery.DatabaseComponentID and Components.MasterDatabasecomponentID from right to inner fixes the error but does not display the records that I need. ComponentMasterCostQuery.DatabaseComponentIDComponents.MasterDatabasecomponentID之间的ComponentMasterCostQuery.DatabaseComponentID从右更改为内部可修复该错误,但不显示我需要的记录。 I am trying to display all records from the Components table and only those from ComponentMasterCostQuerywhere the fields are equal. 我试图显示从组件表中的所有记录,只有那些从ComponentMasterCostQuerywhere领域是相等的。

When the user adds a component to the database I need it to appear in this listbox so they can select it and add other related information stored in other tables. 当用户将组件添加到数据库时,我需要它出现在此列表框中,以便他们可以选择它并添加存储在其他表中的其他相关信息。 Once this information has all been entered the ComponentMasterCostQuery calculates the cost to manufacture the component, the ComponentFinalHomeListboxQuery picks this up and displays a cost in the listbox with the item. 一旦全部输入了此信息, ComponentMasterCostQuery就会计算出制造组件的成本,然后ComponentFinalHomeListboxQuery会选择此成本,并在带有项目的列表框中显示成本。

  • Components is the master table containing all the component Id's, names and types (pulled from the ComponentTypes table). 组件是包含所有组件ID,名称和类型(从ComponentTypes表中拉出)的主表。
  • ComponentTypes simply is a list of types that each component is assigned. ComponentTypes只是每个组件分配的类型的列表。

Here is the SQL from the query in question: 这是有关查询的SQL:

SELECT
    ComponentMasterCostQuery.DatabaseComponentID
  , Components.KadComponentID
  , Components.ComponentName
  , ComponentTypes.Type
  , ComponentMasterCostQuery.PerPartMaterialCost
  , ComponentMasterCostQuery.OperationsCost
  , ComponentMasterCostQuery.TotalManufactureCost
FROM
    ComponentTypes
    RIGHT JOIN
        (ComponentMasterCostQuery
        RIGHT JOIN
            Components
        ON
            ComponentMasterCostQuery.DatabaseComponentID = Components.MasterDatabasecomponentID)
    ON
        ComponentTypes.ID = Components.ComponentType

Apologies if this is something silly, in fumbling my way through access learning from my mistakes! 如果这很愚蠢,我很抱歉,因为我从自己的错误中学到了访问学习的方法!

Thanks for reading if you got this far! 如果您到此为止,感谢您的阅读! Ryan 瑞安

You are missing the = . 您缺少= But aliases make the query easier to write and to read: 但是别名使查询更易于编写和阅读:

SELECT cmcq.DatabaseComponentID,  c.KadComponentID, c.ComponentName, ct.Type, 
       cmcq.PerPartMaterialCost, cmcq.OperationsCost, cmcq.TotalManufactureCost
FROM ComponentTypes as ct RIGHT JOIN
     (ComponentMasterCostQuery as cmcq RIGHT JOIN
      Components as c
      ON cmcq.DatabaseComponentID = c.MasterDatabasecomponentID
     )
     ON ct.ID = c.ComponentType;

I much prefer LEFT JOIN . 我更喜欢LEFT JOIN In fact, I almost never use RIGHT JOIN s. 实际上,我几乎从不使用RIGHT JOIN But I did not change your query. 但是我没有更改您的查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM