错误:子查询返回多行

时间:2017-03-21 22:41:47

标签: postgresql sql-update subquery

我有以下SQL查询(使用Postgre,pgAdmin3)

update "Customers"
set "PID"=(select PID
from person
left join "Customers"
on "Customers"."Email"=person.Email
where "Customers"."Email"!='' and "Customers"."Email" is not null)

子查询运行得很好,并返回与人员表中找到的PID匹配的客户电子邮件列表。

我需要使用此PID列表来更新Customer表中的PID字段。

有什么建议吗?

2 个答案:

答案 0 :(得分:3)

您的查询并不完全清楚,但我认为您正在寻找类似的内容:

update "Customers" as c
set "PID"=p.PID
from person AS p
where c."Email"=p.Email
and c."Email"!='' and c."Email" is not null

答案 1 :(得分:0)

显然,你既是天才也是心灵读者。那就是现场,正是我想要的。

相关问题