Avatar of matthewdacruz
matthewdacruz
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Mysql table update values in one table from another table

Hi Experts

I have two tables in my database.
I want to create a script that updates one table with the values of the second table based on where the usrid matches in the where clause

I am getting errors.

[Err] 1054 - Unknown column 'companyprofile.usrid' in 'where clause'

What is the correct way to do this query?

update usrprofiles 
SET 
usrprofiles.CompanyName = companyprofile.CompanyName,
usrprofiles.CompanyID = companyprofile.CompanyID
WHERE
usrprofiles.usrid = companyprofile.usrid

Open in new window

MySQL ServerDatabases

Avatar of undefined
Last Comment
matthewdacruz

8/22/2022 - Mon
Pratima

update usrprofiles
SET
usrprofiles.CompanyName = companyprofile.CompanyName,
usrprofiles.CompanyID = companyprofile.CompanyID

From companyprofile
WHERE
usrprofiles.usrid = companyprofile.usrid
ASKER CERTIFIED SOLUTION
Pratima

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
matthewdacruz

ASKER
I have tried

update usrprofiles
INNER JOIN companyprofile USING (usrid,CompanyName,CompanyID)
SET
usrprofiles.CompanyName = companyprofile.CompanyName,
usrprofiles.CompanyID = companyprofile.CompanyID
WHERE
usrprofiles.usrid = companyprofile.usrid

That runs but does not update any rows either
matthewdacruz

ASKER
Thanks that did it
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck