繁体   English   中英

如果列与PostgreSQL匹配,则使用来自另一个表的数据更新表的列

[英]Update a column of a table with data from another table if columns match PostgreSQL

在此处输入图片说明 如果列中的值与另一个表中列中的另一个值匹配,我想向列中添加多个值。

例如

table1 column1.1 column1.2

table2 column2.1 column2.2

如果column2.2 = column1.1,则用2.1列更新column1.2

应该能够将多个值写入2.1列

这是我所拥有的,但不起作用。

SET table1.2 = table2.column2.1 from table2 WHERE table1.column1.1 = table2.column2.2

您似乎想要从另一个表进行update 语法如下所示:

update table1
    set column1 = table2.column1 
    from table2 
    where table1.column2 = table2.column2;

在您的问题中,我无法跟随列名的变化,但这是从一个表更新另一个表中的列的结构。

这应该做到-

update table1
    set column1.2 = table1.column1.2 || ' ' || table2.column2.1 
    from table2 
    where table1.column1.1 = table2.column2.2;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM