You are going to join the subquery back to the main table, right? Otherwise it'll always return all the rows in the products table!
Anyway, you could do something like:
- Use count(*) over (partition by <join cols>) to see how many rows there are in products for the account
- Only return rows from the subquery where this count = 1:
create table t1 (
x int,
y int
);
create table t2 (
x int,
z int
);
insert into t1 values (1, 1);
insert into t1 values (1, 2);
insert into t1 values (2, 2);
insert into t2 values (1, 0);
insert into t2 values (2, 0);
update t2
set z = (select y
from (select x, y, count(*) over (partition by x) c from t1) t1
where t1.x = t2.x
and c = 1
);
select * from t2;
X Z
1
2 2