I apologize for confusing and cumbersome question, but anyway I need to do following: In ‘wp_usermeta’ table I have fields (meta_keys) ‘category’ and ‘request_category’ for all users. Now I want overwrite meta_value of ‘category’ with meta_value ‘request_category’ where ‘category’ has a specific value.
But after executing SQL query I’m getting NULL in ‘meta_value’ fields of ‘category’. Here is my code:
UPDATE
wp_usermeta
SET
wp_usermeta.meta_value =
(SELECT
umeta_tmp.meta_value
FROM
umeta_tmp
WHERE umeta_tmp.meta_key = 'request_category'
AND umeta_tmp.umeta_id = wp_usermeta.umeta_id)
WHERE wp_usermeta.meta_key = 'category'
AND wp_usermeta.meta_value = 'travel_agency'
Where table ‘umeta_tmp’ is a temporary table where I kept data of ‘wp_usermeta’ table (since I can’t modify the same table which I use in the SELECT part).
Could anyone hint me how can I achieve that.
Thanks.
Convert into UPDATE with JOIN
If the
umeta_tmp
table is just the copy from thewp_usermeta
table then theJOIN
andWHERE
conditions are contradictious because you want themeta_key
field of the same row (equalization byid
) to be'request_category'
in theumeta_tmp
table and at the same time to be'category'
in thewp_usermeta
.Having this in view and moving the
WHERE
condition into theJOIN
the result will be the following: