简体   繁体   English

如何使用 MySql 使用另一个表中的值更新两个表上的值

[英]How can I update the values on two tables with the values from another table with MySql

I have 3 tables, T1, T2, T3.我有 3 张桌子,T1、T2、T3。 I need to update the stock_status from T1 and limited from T2 with the values from stock_status and limited from T3, only where the sku are matching.我需要更新来自 T1 的 stock_status 并使用来自 stock_status 的值和来自 T3 的限制从 T2 进行限制,仅在 sku 匹配的情况下。 Also the entity_id is the correspondent for product_id.此外,entity_id 是 product_id 的对应者。

Here is an image to understand better这是一张图片可以更好地理解图片

I'm stuck at moving the values from stock_status from T3 in stock_status from T1, since I don't have a common field directly.我一直坚持将 stock_status 中的值从 T1 中的 stock_status 中的 T3 中移出,因为我没有直接的公共字段。

For limited field, I tried.对于有限的领域,我尝试过。

UPDATE t2,t3 INNER JOIN t3 on t2.sku = t3.sku SET t2.limited = t3.limited

You should use add an inner join between t2 and t1 for update also t1.stock_status您应该使用在 t2 和 t1 之间添加一个内部连接来更新 t1.stock_status

  UPDATE t2,t1 
  INNER JOIN t3 on t2.sku = t3.sku 
  INNER JOIN t1 on t1.product_id = t2.entity_id
  SET t2.limited = t3.limited, 
      t1.stock_status = t3.stock_status

Try these试试这些

UPDATE t1
        JOIN
    t2
        JOIN
    t3 
SET 
    t1.stock_status = t3.stock_status
WHERE
    t1.product_id = t2.entity_id
        AND t2.sku = t3.sku;

. .

UPDATE t2
        JOIN
    t3 
SET 
    t2.limited = t3.limited
WHERE
    t2.sku = t3.sku;

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

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