从另一个表和另一个数据库更新表 [英] Update table from another table and different database

查看:59
本文介绍了从另一个表和另一个数据库更新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想做的是以下几点: 我的第一个数据库(prc)中有一个用户"表,如下所示:

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
[...]

在我的第二个数据库(名为:prc_test)中

And in my second database (named : prc_test)

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

我想做的是用来自"prc.user"的pwd_user的值更新"prc_test.user"中的所有"pwd_user"字段. 但是在prc_test.user中,id与prc.user中的ID不同,因此我想到了使用"name_user"(没有双打)的方法.

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).

关于我该怎么做的任何线索? 我在Google上进行了搜索,但发现总是针对某些特定情况或插入语句...

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...

(我正在使用MySQL5.5)

(I'm using MySQL5.5)

谢谢!

推荐答案

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

这篇关于从另一个表和另一个数据库更新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆