Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update table from another table and different database

Tags:

sql

mysql

Basically, what I want to do is the following : I have a table 'users' in my first database (prc), like this :

prc.user : id_user : 45 | name_user : Test | login_user : test | pwd_user : test [...] 

And in my second database (named : prc_test)

prc_test.user id_user : 45 | name_user : Test | login_user : test | pwd_user : test [...] 

The thing I want to do, is update all the "pwd_user" fields in "prc_test.user" with the values from pwd_user from "prc.user" But in the prc_test.user, the id are not the same as in prc.user, so I thought of doing it with the "name_user", (there are no doubles).

Any clue in how I can do it ? I searched on Google, but what I found is always for some specific cases, or for insert statements...

(I'm using MySQL5.5)

Thanks !

like image 282
Yanis Boucherit Avatar asked Aug 24 '12 11:08

Yanis Boucherit


People also ask

How do you update one table from another database table?

INSERT INTO SQL statement is used to insert data from one database table to another. The INSERT INTO can be used to transfer data from one database to other database or between two tables in the same database.


1 Answers

UPDATE    prc.user,    prc_test.user  SET    prc_test.user.pwd_user = prc.user.pwd_user WHERE    prc_test.user.name_user = prc.user.name_user 
like image 163
Dan Grossman Avatar answered Sep 30 '22 21:09

Dan Grossman