-1

I am querying a column using the below statement:

SELECT t1.col1 from table1 t1, table2 t2  
WHERE t1.col1 = t2.col2 and t2.col3 IN (data1, data2);

I am trying to update the t1.col1 satisfying the above where condition but I get errors.

here is the update statement I tried:

update t1 set t1.col1 = 1 from table1 t1 INNER JOIN table2 t2 where t2.col3 IN ( data1, data2 );

I want to update the value of t1.col1 if the listed data matches the data in t2.col3

Kiran Cyrus Ken
  • 379
  • 1
  • 3
  • 17
  • Does this answer your question? [SQL update from one Table to another based on a ID match IN db2](https://stackoverflow.com/questions/23285136/sql-update-from-one-table-to-another-based-on-a-id-match-in-db2) – mustaccio Nov 13 '19 at 11:49

1 Answers1

2

You should be able to use correlated subquery syntax here:

UPDATE table1 t1
SET col1 = 1
WHERE EXISTS (SELECT 1 FROM table2 t2 WHERE t2.col2 = t1.col1 AND t2.col3 IN (data1, data2));
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360