SQL Update a table from another table

倾然丶 夕夏残阳落幕 提交于 2019-12-02 02:34:12

You can do the UPDATE with an INNER JOIN to perform the update you need:

UPDATE A SET
    num_factura = B.num_factura
FROM therefore.dbo.thecat51 A
    INNER JOIN therefore.dbo.Documentos B
        ON A.num_albaran = B.num_albaran

Use an INNER JOIN between your two tables. At the time I posted this, you had not told us which RDBMS you are using so I will give answers for SQL Server and MySQL:

SQL Server:

UPDATE t1 
SET t1.num_factura = t2.num_factura
FROM therefore.dbo.thecat51 AS t1
INNER JOIN therefore.dbo.Documentos AS t2
    ON t1.num_albaran = t2.num_albaran

MySQL:

UPDATE therefore.dbo.thecat51 AS t1
INNER JOIN therefore.dbo.Documentos AS t2
    ON t1.num_albaran = t2.num_albaran
SET t1.num_factura = t2.num_factura
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!