【问题标题】:Multiple Right Join Issue in Ms Access SQL, Returns SYNTAX ERRORMs Access SQL 中的多个右连接问题,返回 SYNTAX ERROR
【发布时间】:2018-10-20 09:36:08
【问题描述】:

我在(我认为)SQL 方面遇到了一些问题。我不是这里的专家,但已经读过多个连接需要用括号括起来,但我就是无法完成这项工作。

也许这甚至不是问题,这很可能是因为我没有完全理解这里发生了什么!如果有人能告诉我我在这里做了什么愚蠢的事情,那就太好了!

当我打开列表框引用此查询的表单时 ComponentFinalHomeListboxQuery 我得到:

"查询表达式中的语法错误(缺少运算符) '[DatabaseComponentID] ='。

列表仍会填充,但会在每条记录出现在列表框中之前显示错误。

ComponentMasterCostQuery.DatabaseComponentIDComponents.MasterDatabasecomponentID 之间的连接从右更改为内可修复错误,但不显示我需要的记录。我正在尝试显示 Components 表中的所有记录,并且只有来自 ComponentMasterCostQuerywhere 字段的记录是相等的。

当用户将组件添加到数据库时,我需要它出现在此列表框中,以便他们可以选择它并添加存储在其他表中的其他相关信息。一旦这些信息全部输入,ComponentMasterCostQuery 就会计算制造该组件的成本,ComponentFinalHomeListboxQuery 会选择该信息并在包含该项目的列表框中显示成本。

  • Components 是包含所有组件 ID、名称和类型的主表(从 ComponentTypes 表中提取)。
  • ComponentTypes 只是每个组件分配的类型列表。

这是来自相关查询的 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

抱歉,如果这是愚蠢的事情,我从错误中摸索通过访问学习的方式!

感谢您阅读到这里! 瑞恩

【问题讨论】:

  • 使用查询设计器构建以获得正确的语法。缺少括号或 1 太多。必须成对。并且缺少 = 符号。
  • 这是和设计师一起建的,我想我在粘贴代码的时候一定是不小心把它们删掉了,它是这样的:
  • 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.Database Components.MasterDatabasecomponentID) ON ComponentTypes.ID = Components.ComponentType;
  • 然后编辑你的问题。
  • 问题已编辑:)

标签: sql ms-access


【解决方案1】:

您缺少=。但是别名使查询更易于编写和阅读:

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;

我更喜欢LEFT JOIN。事实上,我几乎从不使用RIGHT JOINs。但我没有更改您的查询。

【讨论】:

  • 啊,这很方便!好的,这可能会导致我的错误吗?
  • 缺少= 是您出错的最可能原因。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多