所以我有三张表订单、运输和客户。我想在客户表中将进口值更新为"88"。但在PHP代码中,我只有shipping.tracking_id。所以我需要内部连接另一个表(在订单表中,我有customer.id和shipping.orderid(。这些表看起来像这样:
客户
id | 导入 | 等 |
---|---|---|
1234 | 0 | 等 |
5678 | 0 | 等 |
尝试此解决方案
UPDATE `Customers` `cus`
SET `cus`.`import` = 88
WHERE EXISTS(
SELECT * FROM `Shipping` `s`
INNER JOIN `Orders` `o` on `o`.orderid = `s`.`orderid`
WHERE `s`.`tracking_id` = 't5678' AND `cus`.`id` = `o`.`customerid`
);
在Mysql上测试
如果我的理解是正确的,您应该执行以下操作:
- 加入订单运输
- 与客户联合订单
- 添加发货条件.tracking_id
查询如下所示:
UPDATE customers
SET import = '88'
FROM customers c
JOIN orders o on c.id = o.customerid
JOIN shipping s on o.orderid = s.orderid
WHERE s.tracking_id = 't1234';
请尝试以下操作;
update customers set import='88'where id=(从orders.orderid=的订单中选择orders.customerid(从shipping.tracking_id='tracking_id'的发货中选择shipping.orid(