0

I have very basic mysql knowledge (able to update and join tables) and am using phpMYAdmin but I am trying something just beyond my level now. I have looked at many other questions and answers but cannot find a solution for me. I am sure there is a very simple answer. This is what I am trying to do...

usermeta t1 looks like this:
user_id |  meta_key  | meta_value|
---------------------------------------
 1      |   mk1      |  value1  |
 2      |   mk2      |  value2  |
 3      |   desc     |  name    |
 4      |   mk4      |  value4  |
 5      |   desc     |  name    |
 6      |   mk6      |  value6  |
 7      |   mk7      |  value7  |
 8      |   desc     |  name    |
 9      |   mk9      |  value9  |
 10     |   desc     |  name    |

 userdata t2 looks like this:
 user_id  |   desc   |  
 ---------------------
 1        |   bob    |
 2        |   joe    |
 3        |   nancy  |
 4        |   jane   |
 5        |   lee    |
 6        |   jeff   |
 7        |   jill   |
 8        |   scott  |
 9        |   len    |
 10       |   carey  |

I want to update the t1 meta_value column in all the cells wtih the value "name", where the meta_key is "desc", with the data from t2.desc column, and joined where t1.user_id = t2.user_id, but I don't know how to do this! Does anyone have some mysql suggestions?

  • Are these both custom tables? – s_ha_dum Dec 12 '13 at 16:37
  • t1 is acting as the default wp_usermeta table while t2 is a table I created just to get the data in the database for the join and will dump after I find the solution. – user2591811 Dec 12 '13 at 16:39
  • Is this the result of a query? Or is this the database description? Post the description please. – s_ha_dum Dec 12 '13 at 17:09
  • The above is a description of what I am trying to do. – user2591811 Dec 12 '13 at 19:37
  • @user2591811 See my answer. – Ruhul Amin Dec 14 '16 at 14:32
0

You can update just joining both table on comparing same userid. like:

update t1 join
       t2
       on t1.user_id = t2.user_id
    set t1.meta_value = t2.desc;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.