Table of Contents

About

The update statement works on relation, therefore on table but also on view.

Example

From values

update
    employees 
set 
    firstname='nico', 
    lastname='gerard', 
    age = age + 1, 
    last_changed_date = sysdate 
where 
    emp_id = 1;

From a subquery

with primary key

UPDATE target
SET 
( col1, col2, col3 ) =
(
   SELECT 
       col1, 
       col2, 
       col3
   FROM ...
WHERE 
   target.id=id
);

or

UPDATE target
SET 
    col1=subquery.col2,
    col2=subquery.col1,
    col3=subquery.col3
FROM (
   SELECT 
       id, 
       col1, 
       col2, 
       col3
   FROM ...
) as subquery
WHERE 
   target.id=subquery.id;