Need SQL query to update the column using case when by joining two tables in Netezza Database

Viewed 22

There are 2 tables : Sales & Transaction. I need to update the INDICATOR column of the Sales table using CASE WHEN by joining these two tables in Netezza database.

Using below query but not working. Error - Update canceled: attempt to update a target row with values from multiple join rows

Update Sales s 
SET indicator = 
 CASE  
     WHEN  t.retail >= s.PRICe then 'Y'
     WHEN  t.retail <  s.PRICE then 'N'
     ELSE NULL END
FROM TRANSACTION t
     WHERE s.id = t.id and s.STORE_ID = t.store_id;
1 Answers

It seems you have a relationship in your where clause as one to many. Try to unique identify rows in the Sales table you want to update. Now you are trying to update one row in sales several times and the SQL engine doesn´t know which update should be correct and interrupts the update.

Related