Solved

MySql Inner Join Update Query

Posted on 2013-12-26
6
757 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Syntax 5 37
SSRS 2012 r2 - Parm Drop Down has Date/Time 12 33
Syntax for query to update table 2 15
Filtering characters in an SQL field 2 8
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

831 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