EasyINSERT, UPDATE, DELETE

INSERT FROM SELECT: copy data between tables

The query

SQL
INSERT INTO salary_history (emp_id, old_salary, new_salary, reason)
SELECT
  emp_id,
  salary AS old_salary,
  salary * 1.10 AS new_salary,
  'Annual increment 2024'
FROM employees
WHERE status = 'active'
  AND hire_date < '2024-01-01';
Tested against PostgreSQL 16

Note

INSERT INTO ... SELECT is the SQL way to copy/transform data. Works across tables.

Tables referenced