[英]how to insert values into a column of a table in successive rows by fetching values from a column in a row with a same id in another table
在我的應用程序中,我使用PostgreSQL數據庫。 我有兩個表,即wc_content_definition
和simple_web_content
。 字段web_content_definition_id
是wc_content_definition
表的主鍵, simple_web_content
是simple_web_content_id
的主鍵。 我在simple_web_content
添加了名為web_content_definition_id
字段,我想用wc_content_definition
表中的正確值在所有行中填充此字段。 wc_content_definition
表中名為web_content_id
的列存儲該行的simple_web_content_id
值,而我試圖使用該值來獲取web_content_definition_id
並將其值插入simple_web_content
表中的相應行中。 我要使用的查詢是:
update simple_web_content set web_content_definition_id = (select
wcd.web_content_definition_id from wc_content_definition wcd,
simple_web_content swc where simple_web_content_id = wcd.web_content_id )
and swc.simple_web_content_id <> 0 and wcd.web_content_id <> 0;
我收到以下錯誤:
錯誤:表“ swc”第3行缺少FROM子句條目:... simple_web_content_id = wcd.web_content_id)和swc.simple ...
錯誤錯誤:缺少表“ swc”的FROM子句條目SQL狀態:42P01字符:209
我正在使用pg-admin工具來執行查詢
update simple_web_content
set web_content_definition_id = wcd.web_content_definition_id
from wc_content_definition wcd
WHERE simple_web_content_id = wcd.web_content_id
AND simple_web_content_id <> 0 and wcd.web_content_id <> 0;
在您擁有的查詢中,無法在子查詢之外引用表wc_content_definition
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.