SQL UPDATE

From NovaOrdis Knowledge Base
Revision as of 21:14, 30 May 2024 by Ovidiu (talk | contribs) (→‎Conditional UPDATE)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Internal

Overview

UPDATE person SET name = 'Binh Ngo Jr.', city = 'San Francisco' WHERE id = 1;
PostgreSQL MySQL

The UPDATE statement may contain a WHERE clause, that identifies the rows to be modified:

The WHERE Clause

Conditional UPDATE

UPDATE customer
SET active =
  CASE
    WHEN 90 <= (SELECT datediff(now(), max(rental_date))
                FROM rental r
                WHERE r.customer_id = customer.customer_id)
      THEN 0
    ELSE 1
  END
WHERE active = 1;

Also see:

SQL Conditional Logic