MySQL 从另一个表和不同的数据库更新表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12108690/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Update table from another table and different database
提问by Yanis Boucherit
Basically, what I want to do is the following : I have a table 'users' in my first database (prc), like this :
基本上,我想做的是以下内容:我的第一个数据库(prc)中有一个表“用户”,如下所示:
prc.user :
id_user : 45 | name_user : Test | login_user : test | pwd_user : test
[...]
And in my second database (named : prc_test)
在我的第二个数据库中(名为: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).
我想做的事情是使用来自“prc.user”的 pwd_user 中的值更新“prc_test.user”中的所有“pwd_user”字段但是在 prc_test.user 中,id 与 prc.user 中的不同,所以我想用“name_user”来做,(没有双打)。
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)
(我使用的是 MySQL5.5)
Thanks !
谢谢 !
回答by Dan Grossman
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