MySQL update query with WHERE clause and INNER JOIN not working

时光总嘲笑我的痴心妄想 提交于 2019-12-05 14:09:07

The query should be as below, you have joined the same table and hence the problem of unique alias. I have added table alias for better readability.

UPDATE 
sales_flat_order sfo
INNER JOIN sales_flat_order_grid sfog 
ON sfog.entity_id = sfo.entity_id      
SET sfo.coupon_code = "newcoupon"
WHERE sfog.increment_id = "12345678" ; 

You need to update sales_flat_order and join on sales_flat_order_grid - you've joined on sales_flat_order:

UPDATE sales_flat_order 
INNER JOIN sales_flat_order_grid 
      ON sales_flat_order_grid.entity_id = sales_flat_order.entity_id      
WHERE sales_flat_order_grid.increment_id = "12345678"
SET coupon_code = "newcoupon";

Yo have two times sales_flat_order, change with sales_flat_order_grid

UPDATE sales_flat_order
INNER JOIN sales_flat_order_grid ... -- Need change the namme of the table

If you want to join with the same table, use ALIAS

UPDATE sales_flat_order AS sfo1
INNER JOIN sales_flat_order AS sfo2 ...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!