# UPDATE from joined table

**URL:** <https://community.cratedb.com/t/update-from-joined-table/488>\
**Category:** SQL\
**Created:** [September 7, 2020, 9:49am UTC](https://community.cratedb.com/t/update-from-joined-table/488 "2020-09-07T09:49:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jurgen\_Zornig](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/jurgen_zornig/32/183_2.png) [@Jurgen\_Zornig](https://community.cratedb.com/u/Jurgen_Zornig)\
**Post date:** [September 7, 2020, 9:49am UTC](https://community.cratedb.com/t/update-from-joined-table/488/1 "2020-09-07T09:49:23Z")

</div>

I’m curious if there isn’t any way to UPDATE a table field by getting the value from a joined table…

Neither

```
UPDATE table1 as t1
set xyz = (select xyz from table2 where ref_t1 = t1.id limit 1);

```

nor

```
UPDATE table1 as t1 JOIN table2 as t2 on t2.ref_t1 = t1.id
set xyz = t2.xyz;

```

do work. I assume that I have to solve this via any external (scripted) approach, is that correct?

---

<div class="post-metadata">

**Author:** ![proddata](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/proddata/32/1379_2.png) [@proddata](https://community.cratedb.com/u/proddata)\
**Post date:** [September 18, 2020, 7:51am UTC](https://community.cratedb.com/t/update-from-joined-table/488/2 "2020-09-18T07:51:45Z")

</div>

Hi @Jurgen_Zornig,

I don’t think this is possible yet. Might I suggest, that you open a feature request at [https://github.com/crate/crate/issues](https://github.com/crate/crate/issues)

Best regards  
Georg

---

<div class="post-metadata">

**Author:** ![hernanc](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/hernanc/32/676_2.png) [@hernanc](https://community.cratedb.com/u/hernanc)\
**Post date:** [October 11, 2023, 2:09pm UTC](https://community.cratedb.com/t/update-from-joined-table/488/3 "2023-10-11T14:09:01Z")

</div>

@Jurgen_Zornig in this case you may want to do something like this:

```sql
CREATE TABLE table1 (id INT PRIMARY KEY,xyz TEXT);
INSERT INTO table1 VALUES (1,'old value');

CREATE TABLE table2 (ref_t1 INT,xyz TEXT,version INT);
INSERT INTO table2 VALUES 
	(1,'new value',1),
	(1,'even newer value',2);

INSERT INTO table1(id,xyz)
SELECT ref_t1,max_by(xyz,version)
FROM table2
GROUP BY ref_t1
ON CONFLICT (id) DO UPDATE SET xyz=excluded.xyz;

```
