在mysql更新查询中需要帮助

时间:2016-07-13 13:53:23

标签: mysql

伙计我被困在MySql查询上。以下是我对数据库中SELECT数据的查询。我停留在Update查询以更新Price

Select Query

SELECT p.id, p.post_title, m.meta_key as Type, m.meta_value as SKU ,k.meta_value as price 
FROM wp8k_posts p 
INNER JOIN wp8k_postmeta m ON p.id=m.post_id 
AND m.meta_key='_sku'
INNER JOIN wp8k_postmeta k ON p.id=k.post_id
AND k.meta_key='_sale_price'
where m.meta_value= 'GLC-LH-SM'

Update Query

Update wp8k_postmeta k
INNER JOIN wp8k_posts p ON p.id=m.post_id 
AND m.meta_key='_sku'
INNER JOIN wp8k_postmeta k ON p.id=k.post_id 
AND k.meta_key='_sale_price'
set k.meta_key = 90
where m.meta_value= 'GLC-LH-SM'

任何人都可以帮忙。

1 个答案:

答案 0 :(得分:0)

您必须对所有表使用唯一别名:

Update wp8k_postmeta k 
INNER JOIN wp8k_posts p  ON p.id=k.post_id AND k.meta_key='_sale_price'
INNER JOIN wp8k_postmeta m ON p.id=m.post_id AND m.meta_key='_sku'
set k.meta_key = 90
where m.meta_value= 'GLC-LH-SM'