我在此之前阅读了各种帖子。但它们似乎都不适合我。
正如标题所示,我正在尝试从另一个表中的列更新一列。我不记得以前遇到过这个问题..
1。表:user_settings.contact_id,我想用contacts.id更新where (user_settings.account_id == contacts_account_id)
2。以前,通过account_id将通讯录与用户帐户相关联。不过,现在我们要通过user_settings
contacts.id
相关联
以下是我尝试过的一些例子,尽管它们都没有奏效。我会感兴趣的是A.)为什么他们不工作和B.)我该怎么办呢。
示例A:
UPDATE user_settings
SET user_settings.contact_id = contacts.id
FROM user_settings
INNER JOIN contacts ON user_settings.account_id = contacts.account_id
例B:
UPDATE (SELECT A.contact_id id1, B.id id2
FROM user_settings A, contacts B
WHERE user_settings.account_id = contacts.account_id)
SET id1 = id2
示例C:
UPDATE user_settings
SET user_settings.contact_id = (SELECT id
FROM contacts
WHERE (user_settings.account_id = contacts.account_id)
WHERE EXISTS ( user_settings.account_id = contacts.account_id )
我觉得我的大脑只是关闭了我,并希望重新启动它的任何颠簸。谢谢:))
答案 0 :(得分:38)
根据MySQL文档,要进行跨表更新,您不能使用连接(就像在其他数据库中一样),而是使用where子句:
http://dev.mysql.com/doc/refman/5.0/en/update.html
我认为这样的事情应该有效:
UPDATE User_Settings, Contacts
SET User_Settings.Contact_ID = Contacts.ID
WHERE User_Settings.Account_ID = Contacts.Account_ID
答案 1 :(得分:0)
Update tabelName Set SanctionLoad=SanctionLoad Where ConnectionId=ConnectionID
go
update tabelName Set meterreading=meterreading where connectionid=connectionid
go
update tabelName set customername=setcustomername where customerid=customerid