MySql Inner Join Update Query

I have a meta field for a WordPress user called business_website that holds the company url. I need to update the user_url file in the wp_users table with the value from this business_website meta field.

I can construct a simple update query but since this needs some kind of join I'm unsure.

Please help.
webdorkAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
SharathConnect With a Mentor Data EngineerCommented:
Do you have business_website in another table. If both columns in  same table, you can try this.

Update wp_users
      Set user_url = business_website

If business_website is in another table, what is the joining condition between both the tables. If you know, you can try like this.

Update wp_users t1
    Join  OtherTable t2
      On t1.Col = t2.Col
      Set t1.user_url = t2.business_website
0
 
webdorkAuthor Commented:
yes another table: wp_usermeta the linking fields are as follows:


linkage fields
wp_usermeta:user_id
wp_users:id

date fields
wp_usermeta:business_website
wp_users:user_url

I'd like to add a where clause to test before I change 500 records.
where id=123
0
 
SharathData EngineerCommented:
Update wp_users t1
    Join  wp_usermeta t2
      On t1.id = t2.user_id
      Set t1.user_url = t2.business_website
where t1.id = 123;
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
webdorkAuthor Commented:
Update wp_users t1

Or

Update t1.wp_users
0
 
SharathData EngineerCommented:
Update wp_users t1

Run the command and let me know if you get any error.
0
 
webdorkAuthor Commented:
lovely, thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.