如果在phpMyAdmin中具有特定值,则从另一个表更新表列字段

时间:2015-03-19 08:12:16

标签: mysql sql phpmyadmin

我不是phpMyAdmin大师所以我想你可能很容易。

在Magento数据库上我需要

update sales_flat_order volumn customer_group_id

where the customer_group_id = 0

我想让它更新另一个表中的值: 从表customer_entity获取,列名为group_id 所以总之我想这样做:

UPDATE sales_flat_order column "customer_group_id" where "customer_group_id" = 0

customer_group_id的新值应来自customer_entity字段group_id

在phpmyadmin SQL中输入什么内容?

我的想法,这会有用吗?

    UPDATE sales_flat_order WHERE customer_group_id=0
SET sales_flat_order.customer_group_id=(SELECT customer_entity.group_id
FROM customer_entity
WHERE customer_entity.entity_id=sales_flat_order.customer_id);

1 个答案:

答案 0 :(得分:1)

您需要使用join并更新为

update sales_flat_order sfo 
join customer_entity ce on ce.entity_id = sfo.customer_id
set sfo.customer_group_id = ce.group_id
where sfo.customer_group_id=0