UPDATE statement
The UPDATE statement modifies existing rows in a table, setting one or more column values for rows that match an optional WHERE condition.
Overview
UPDATE is one of the core DML statements, alongside INSERT and DELETE, for changing data already stored in a table. Its basic form sets new values for specified columns on every row matching a WHERE clause:
Copy code
UPDATE orders
SET status = 'shipped', shipped_at = CURRENT_TIMESTAMP
WHERE order_id = 1042;
Omitting WHERE updates every row in the table, so it's worth double-checking the filter before running an UPDATE in production.
Updating from another table
A common need is to update a table's values based on a join against another table — for example, refreshing denormalized totals from a source of truth. Standard SQL and most engines support an UPDATE ... FROM (or UPDATE ... JOIN in MySQL) form for this:
Copy code
UPDATE orders o
SET customer_name = c.name
FROM customers c
WHERE o.customer_id = c.id;
DuckDB specifics
DuckDB supports UPDATE ... SET ... FROM ... WHERE ... exactly as shown above, letting you update a table using values joined from one or more other tables or subqueries. DuckDB also supports a RETURNING clause, which returns the updated rows (post-update values) directly from the UPDATE statement — useful for verifying a change or feeding it into a downstream step without a separate SELECT:
Copy code
UPDATE orders
SET status = 'cancelled'
WHERE order_id = 1042
RETURNING order_id, status, updated_at;
Because DuckDB is transactional, an UPDATE inside an explicit BEGIN ... COMMIT block is atomic and can be rolled back if a later statement in the same transaction fails.
Related terms
The DELETE statement removes rows from a table that match an optional WHERE condition, without dropping the table itself.
UPSERT →UPSERT is a database operation that inserts a new row or updates an existing one if a matching row already exists, typically expressed with an ON CONFLICT clause.
INSERT statement →The INSERT statement is a fundamental SQL command used to add new rows of data into a table.
MERGE statement →MERGE INTO is a SQL statement that inserts, updates, or deletes rows in a target table based on how they match rows from a source table, in a single atomic operation.
CREATE TABLE statement →The CREATE TABLE statement is a fundamental SQL command that defines a new table in a database, specifying its structure including column names, data types,…
ALTER TABLE statement →The ALTER TABLE statement allows you to modify the structure of an existing database table without having to recreate it from scratch.
FAQS
Every row in the table gets updated with the new SET values, since there is no condition restricting which rows are affected. Always double-check the WHERE clause before running an UPDATE, especially in production.
Yes, using UPDATE ... SET ... FROM other_table WHERE join_condition, which lets you set column values based on a join against another table or subquery.
