Mysql 使用两个表更新语句

Mysql 使用两个表更新语句,mysql,sql,Mysql,Sql,我需要将installed products表中的cust设置为Customers表中的ID,尝试了一些没有运气的语句;只需要指向正确的方向 以下是我所拥有的: UPDATE InstalledProducts SET InstalledProducts.cust = Customers.ID FROM InstalledProducts, Customers WHERE InstalledProducts.SiteName = Customers.SiteName 非常感谢您的帮助。

我需要将installed products表中的cust设置为Customers表中的ID,尝试了一些没有运气的语句;只需要指向正确的方向

以下是我所拥有的:

UPDATE InstalledProducts
    SET InstalledProducts.cust = Customers.ID
FROM InstalledProducts, Customers
WHERE InstalledProducts.SiteName = Customers.SiteName

非常感谢您的帮助。谢谢

带有JOIN的update语句应该如下

update 
InstalledProducts ip
join Customers c on c.SiteName = ip.SiteName
set ip.cust = c.ID

我会这样写:

UPDATE InstalledProducts ip
    SET cust = 
(SELECT ID FROM Customers
WHERE ip.SiteName = SiteName)