Sql 两个表的内部查询和联接
我有一个ChildTable,我需要更新它的列 其中,条件值从父表Id列中拾取Sql 两个表的内部查询和联接,sql,Sql,我有一个ChildTable,我需要更新它的列 其中,条件值从父表Id列中拾取 Update ChildTable set Column1 = 'Value', Column2 = 'Value2' Where ChildTable.Id = 100 试着跟随 Update ChildTable set Column1 = 'Value', Column2 = 'Value2' from ChildTable ct inner join parenttable pt on pt.key =
Update ChildTable set Column1 = 'Value', Column2 = 'Value2'
Where ChildTable.Id = 100
试着跟随
Update ChildTable set Column1 = 'Value', Column2 = 'Value2'
from ChildTable ct
inner join parenttable pt on pt.key = ct.parentkey
Where ChildTable.Id = pt.parentconditionfield
首先使用select并确保您获得了要更新的正确记录 由于你没有给出正确的信息,但从你的例子中,我得出了这个结论
SELECT c_t.column1, c_t.column2
FROM parent_table p_t inner join child_table c_t
ON p_t.pk_column = c_t.fk_column
WHERE c_t = 100;
UPDATE c_t
set c_t.column1 = 'Value', c_t.column2 = 'Value2'
FROM parent_table p_t inner join child_table c_t
ON p_t.pk_column = c_t.fk_column
WHERE c_t = 100;
@FilipeSilva是否
使用Join更新
查询在每个RDBMS中都是不同的?有些DBMS根本不允许这样做。不同的数据库管理系统也存在差异。