Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 两个表的内部查询和联接_Sql - Fatal编程技术网

Sql 两个表的内部查询和联接

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 =

我有一个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 = 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根本不允许这样做。不同的数据库管理系统也存在差异。