SQLite Forum

Updating a value with one from another table?
Login
The table t1 is already included in the set of tables and does not need to be listed twice (unless you want to use it twice).  This is different from some other SQL versions in which `UPDATE <table> SET ... FROM <table> WHERE ...` the `<name>` after the UPDATE is merely describing which table in the join is to be updated and the syntax form is merely an implementation of UPDATE ... WHERE CURRENT OF CURSOR.

See <https://sqlite.org/lang_update.html> in particular ss 2.2

You probably mean:

```
update t1
   set zipcode = t2.zipcode
  from t2
 where t2.code_stat = t1.code_stat
;
```

or as a correlated query:

```
update t1
   set zipcode = (
                  select zipcode
                    from t2
                   where t2.code_stat = t1.code_stat
                 )
 where exists (
               select *
                 from t2
                where t2.code_stat = t1.code_stat
              )
;
```

both of the above being identical in effect -- the first one being shorter to type and resulting in a better plan.