la_f0ka
la_f0ka

Reputation: 1773

Need help with simple MySQL query

I have a table with 4 values, meta_id, post_id, meta_key and meta_value, and I want to change all meta_values found as "yes" to "si" when the meta_key is stock_available... how do I do this?. I cannot even retrieve the rows at this point...I'm trying with something like this.

SELECT `meta_value` FROM `wp_postmeta` WHERE `meta_key` AND `meta_value` = 'yes'

Could I have some help?

EDIT: I had forgotten the meta_key...

SELECT * FROM `wp_postmeta` WHERE `meta_key` = 'stock_available' AND `meta_value` =  yes'

So I retrieve these... btu how do I update them?

Upvotes: 0

Views: 64

Answers (2)

Joe Stefanelli
Joe Stefanelli

Reputation: 135938

UPDATE wp_postmeta
    SET meta_value = 'si'
    WHERE meta_key = 'stock_available'
        AND meta_value = 'yes';

Upvotes: 1

Adam Batkin
Adam Batkin

Reputation: 53034

You need to use the SQL UPDATE statement:

UPDATE wp_postmeta SET meta_value = 'si' WHERE meta_value = 'yes' AND meta_key = 'stock_available'

Before you do that, run this SELECT to make sure that you are going to be updating the correct rows:

SELECT * FROM wp_postmeta WHERE meta_value = 'yes' AND meta_key = 'stock_available'

Upvotes: 1

Related Questions