Solved

MySql Inner Join Update Query

Posted on 2013-12-26
6
750 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
  • 3
  • 3
6 Comments
 
LVL 40

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 40

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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:webdork
ID: 39742492
Update wp_users t1

Or

Update t1.wp_users
0
 
LVL 40

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now