monchichi
monchichi

Reputation: 47

Update table column field form another table if its a specific value in phpMyAdmin

I am no phpMyAdmin guru so I guess it may be very easy for you.

On a Magento database I need to

update sales_flat_order volumn customer_group_id

where the customer_group_id = 0

and I want it to update the value from another table: take it from table customer_entity and column name is group_id so in short I want to do this:

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

and the new value of customer_group_id should be from customer_entity field group_id.

What to enter in phpmyadmin SQL ?

My idea, would this work?

    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);

Upvotes: 0

Views: 1652

Answers (1)

Abhik Chakraborty
Abhik Chakraborty

Reputation: 44874

You need to use join and update as

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

Upvotes: 1

Related Questions