</>
Skip to content
PostgreSQL lessons (13/38)

PostgreSQL — Update

Basic Update

UPDATE users SET name = 'Jane' WHERE id = 1;

Multiple Columns

UPDATE users 
SET name = 'Jane', email = 'jane@example.com' 
WHERE id = 1;

Update All Rows

UPDATE users SET active = true;

With Subquery

UPDATE users 
SET country = 'USA' 
WHERE id IN (SELECT id FROM orders WHERE total > 100);

Returning

UPDATE users 
SET name = 'Jane' 
WHERE id = 1 
RETURNING *;

Using Expression

UPDATE products 
SET price = price * 1.1 
WHERE category = 'electronics';

Conditional Update

UPDATE users 
SET status = CASE 
    WHEN age > 18 THEN 'adult'
    ELSE 'minor'
END;

Mini Practice

  1. Update single row
  2. Update multiple columns
  3. Use expressions
  4. Return updated data

Up Next

Continue with Delete — deleting data.

Related Topics

Frequently Asked Questions about Update

What is Update in PostgreSQL?

Update is a fundamental concept in PostgreSQL. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Update?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Update.

Why is Update important in PostgreSQL?

Update is essential for PostgreSQL development. Understanding this concept will help you write better code and solve real-world problems more effectively.