---
title: "PostgreSQL UPDATE Join "
description: "This query shows how to use the PostgreSQL UPDATE join syntax to update data in a table based on values in another table. for example;"
canonical: https://oozou.com/til/postgresql-update-join-64
locale: en
date: 2020-10-13
topic: ruby-on-rails
---

# PostgreSQL UPDATE Join 

> This query shows how to use the PostgreSQL UPDATE join syntax to update data in a table based on values in another table. for example;

Published: 2020-10-13 · Topic: [ruby on rails](https://oozou.com/til-topics/ruby-on-rails) ([markdown](https://oozou.com/til-topics/ruby-on-rails.md))

This query shows how to use the PostgreSQL UPDATE join syntax to update data in a table based on values in another table. for example;

updating *subscription\_missions.giftbox\_type* with *rewards.gift\_box\_type* through *mission\_rewards* table (tested on 300k records, crazy level fast)

```sql
  UPDATE
        subscription_missions sm
  SET
        giftbox_type = r.gift_box_type
  FROM
        mission_rewards mr,
        rewards r
  WHERE
        sm.giftbox_type IS NULL
        AND sm.id = mr.subscription_mission_id
        AND mr.reward_id = r.id;
```

---

Contact OOZOU: hello@oozou.com · +66 2544 0000 · https://oozou.com/contact

More for AI agents: https://oozou.com/llms.txt · every page has a markdown twin at its URL plus ".md"
