sql - Postgresql Update using Inner Join set -
I have two tables that they share two fields (Marfeld 1, Marfield 2) and two tables Interested in 2 other fields in one
What I want to do here: 1. Join the internal two tables 2. Update a table (field 1) on the table based on another field (field or other field) field, No.
The code below runs fine but the Target set field (Field 1) does not update anything.
update table 2 set field 1 = (case when os.afield is not zero (os.afield) Els os.anotherfield termination) Internal table 2 FD ON Fd.myfield1 = Os myfield1 and fd.myfield2 = os.myfield2;
update table 2 fd set fd.field1 = (select case When the OS is not far away, the zero (OSAFILD) other OSAuthor field ends with 1 table where fd.myfield1 = os.myfield1 and fd.myfield2 = os.myfield2);
This is called a correlated subquery, which is executed for each row in Table 2. But you should make sure that the subquery returns one or zero rows
This query will update all the rows in Table 2 if you want to update only those rows that exist in Table 1 You need WHERE
update table 2 fd set fd.field1 = (select when os.afield is not zero (os.afield) where other osanotherfield termination table 1 OS fd. Myfield1 = os.myfield1 and fd.myfield2 = os.myfield2) where exists (Table 1 of OS 1 Select where FD .myfield1 = os.myfield1 and fd.myfield2 = os.myfield2);
Comments
Post a Comment