Reputation: 69
I am trying to update the table if min_failed from bx_temp is smaller than the current min_failed value in the table.
I keep getting a "min_failed is ambiguous" referring to the min_failed in my case statement. I can't assign it a table alias either though.
with c as (select * from b_temp)
update table b
set min_failed = (select case when ct.min_failed < min_failed then ct.min_failed else min_failed end)
from c
where c.user = b.user
Upvotes: 0
Views: 616
Reputation: 7451
I'm not able to test the query, but you can modify it like so:
WITH c AS (SELECT * FROM b_temp)
UPDATE table b
SET min_failed = LEAST(c.min_failed,b.min_failed)
-- Use LEAST() instead of case logic. Also fixes your error because you were using SELECT without a FROM
FROM c
WHERE c.user = b.user;
Upvotes: 2