SoFunction
Updated on 2025-04-08

Postgresql two table association update operation

I won't say much nonsense, let's just read the code~

UPDATE Table to be updated
SET Fields1 = cqt.Fields1,
 Fields2 = cqt.Fields2,
FROM
 Data source table cqt
WHERE
 Table to be updated.bsm = 

Supplement: Postgresql continuous table update field syntax update

The following section of SQL was originally intended to update the data under conditions, but this section of SQL updated the data of the entire table. SQL is as follows:

UPDATE tops_visa.visa_order
SET op_audit_abort_pass_date = now()
FROM
 tops_visa.visa_order as t1
INNER JOIN tops_visa.visa_visitor as t2 
ON t1. ID = t2.order_id
WHERE
 t1.op_audit_abort_pass_date IS NULL
AND (
 t2. STATE = 'pch_abort_op_audit_pass'
 OR t2. STATE = 'pvd_abort_op_audit_pass'
)
 

There are many correct writing methods, and the following methods can also implement correct database modification:

UPDATE tops_visa.visa_order as t1
SET op_audit_abort_pass_date = now()
FROM
 tops_visa.visa_visitor AS t2
WHERE
  = t2.order_id
AND t1.op_audit_abort_pass_date IS NULL
AND (
 t2. STATE = 'pch_abort_op_audit_pass'
 OR t2. STATE = 'pvd_abort_op_audit_pass'
)

The above is personal experience. I hope you can give you a reference and I hope you can support me more. If there are any mistakes or no complete considerations, I would like to give you advice.