> ... that is to say, update table_a.value from table_b.value, but only
> on rows where table_a.key = table_b.key

update table_a set value =
(select table_b.value from table_b where table_b.key = table_a.key)


Pavel


On Fri, Apr 1, 2011 at 8:42 PM, Robert Poor <rdp...@gmail.com> wrote:
> I'd like to be able to update specific records in table A from joined
> records in table B. So for example:
>
> CREATE TABLE "table_a" ("key" integer, "value" float);
> CREATE TABLE "table_b" ("key" integer, "value" float);
> INSERT INTO "table_a" ("key", "value") VALUES (1,   1.0), (2,   2.0),(3,   
> 3.0);
> INSERT INTO "table_b" ("key", "value") VALUES (1, 101.0), (2, 102.0),(4, 
> 104.0);
>
> In an imaginary version of SQLite ;) this might be written as:
>
> # UPDATE table_a
> #   JOIN table_b
> #    SET table_a.value = table_b.value
> #  WHERE table_a.key1 = table_b.key
>
> resulting in table_a:
>
> key | value
> 1   | 101
> 2   | 102
> 3   |   3
>
> ... that is to say, update table_a.value from table_b.value, but only
> on rows where table_a.key = table_b.key
>
> I've pored over the UPDATE syntax, but I don't see a way to do this.
> What's the idiom in SQLite?
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to