尝试从一个 table 中获取列值并使用 UPDATE & JOIN 将其更新为另一个

Trying to take column value from one table and update it into another using UPDATE & JOIN

MS Access,使用 SQL,尝试了以下 this post--

我的objective是用tbl_line_items.Order_Numbertbl_line_items.Line_Number作为主键,取列值tbl_line.items_Product_Line,更新为tbl_MTO_vs_ETO.ProductLine .

基本上,我想获取产品线及其各自的产品线和订单号,并将其插入 MTO 与 ETO table。

当前代码:

UPDATE tbl_line_items INNER JOIN tbl_MTO_vs_ETO ON (tbl_line_items.Order_Number = tbl_MTO_vs_ETO.Order) AND (tbl_line_items.Line_Number = tbl_MTO_vs_ETO.Line) AND (tbl_line_items.Product_Line = tbl_MTO_vs_ETO.ProductLine) 
SET tbl_MTO_vs_ETO.ProductLine = [tbl_MTO_vs_ETO].[ProductLine]=[tbl_line_items].[Product_Line];

我的查询已追加,但 returns 没有任何内容(“您将要更新 0 行”)。我相信我应该使用 UPDATE 语句,因为记录已经存在,我最近刚刚添加了该产品线列以进行进一步过滤。

对于nbk--

我 运行 一个 SELECT 和 JOIN 查询,并且能够成功拉出分片顺序和行号,并找到每条记录的产品行。现在的问题是,我如何运行将其转换为 UPDATE 查询?

代码:

SELECT tbl_line_items.Product_Line, tbl_line_items.Order_Number, tbl_line_items.Line_Number
FROM tbl_MTO_vs_ETO INNER JOIN tbl_line_items ON (tbl_MTO_vs_ETO.line = tbl_line_items.Line_Number) AND (tbl_MTO_vs_ETO.Order = tbl_line_items.Order_Number);

你的SELECT有两个条件

SELECT 
    tbl_line_items.Product_Line,
    tbl_line_items.Order_Number,
    tbl_line_items.Line_Number
FROM
    tbl_MTO_vs_ETO
        INNER JOIN
    tbl_line_items ON (tbl_MTO_vs_ETO.line = tbl_line_items.Line_Number)
        AND (tbl_MTO_vs_ETO.Order = tbl_line_items.Order_Number);

但是你的UPDATE有三个

UPDATE tbl_line_items 
   INNER JOIN tbl_MTO_vs_ETO 
   ON (tbl_line_items.Order_Number = tbl_MTO_vs_ETO.Order) AND (tbl_line_items.Line_Number = tbl_MTO_vs_ETO.Line) AND (tbl_line_items.Product_Line = tbl_MTO_vs_ETO.ProductLine) 
SET tbl_MTO_vs_ETO.ProductLine = [tbl_MTO_vs_ETO].[ProductLine]=[tbl_line_items].[Product_Line];

必须满足这三个条件才能发生 UPDATE

所以使用

UPDATE 
    tbl_MTO_vs_ETO
        INNER JOIN
    tbl_line_items ON (tbl_MTO_vs_ETO.line = tbl_line_items.Line_Number)
        AND (tbl_MTO_vs_ETO.Order = tbl_line_items.Order_Number);
SET tbl_MTO_vs_ETO.ProductLine = [tbl_MTO_vs_ETO].[ProductLine]=[tbl_line_items].[Product_Line];

这样 UPDATE 就可以工作了