0
我有一個ChildTable,我需要更新它的列。內部查詢和兩個表的連接
其中,條件值是從父表格Id列中選取的。
Update ChildTable set Column1 = 'Value', Column2 = 'Value2'
Where ChildTable.Id = 100
我有一個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 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;
什麼是您的DBMS? –
@FilipeSilva在每個RDBMS中'Update with Join'查詢是否有所不同? –
有一些DBMS根本不允許它。不同的DBMS也有差異。 –