Oracle SQL: Update a table with data from another table

In Oracle SQL, you can use the "UPDATE" statement to update a table with data from another table. The basic syntax for the statement is as follows:

UPDATE target_table
SET target_table.col1 = source_table.col1,
    target_table.col2 = source_table.col2,
    ...
FROM source_table
WHERE target_table.id = source_table.id;
  • target_table: the table that you want to update
  • source_table: the table that you are using to update from
  • id: the column that is used to match rows between the two tables
For example:

UPDATE employees e
SET e.salary = s.salary
FROM salaries s
WHERE e.employee_id = s.employee_id;

This will update the salary of the employee's table with the salary from the salaries table, where the employee_id match between the two tables. You can also use the JOIN clause to join the two tables and use the columns from both tables in the update statement.

UPDATE employees e
SET e.salary = s.salary
FROM employees e

In this example, the two tables, "employees" and "salaries" are joined on employee_id, and the salary of the employee's table is updated with the salary from the salaries table.