← Back to Glossary

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

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.