Solved

MySql Inner Join Update Query

Posted on 2013-12-26
6
765 Views
Last Modified: 2014-01-02
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.
0
Comment
Question by:webdork
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 41

Accepted Solution

by:
Sharath earned 500 total points
ID: 39741072
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
 

Author Comment

by:webdork
ID: 39741155
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
 
LVL 41

Expert Comment

by:Sharath
ID: 39742280
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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 

Author Comment

by:webdork
ID: 39742492
Update wp_users t1

Or

Update t1.wp_users
0
 
LVL 41

Expert Comment

by:Sharath
ID: 39743935
Update wp_users t1

Run the command and let me know if you get any error.
0
 

Author Closing Comment

by:webdork
ID: 39752082
lovely, thank you.
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Creating and Managing Databases with phpMyAdmin in cPanel.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question