A bit redundant, but how about:

CREATE TABLE table_a (akey integer, avalue float);
CREATE TABLE table_b (bkey integer, bvalue float);
INSERT INTO table_a (akey, avalue) VALUES (1,   1.0);
INSERT INTO table_a (akey, avalue) VALUES (2,   2.0);
INSERT INTO table_a (akey, avalue) VALUES (3,   3.0);
INSERT INTO table_b (bkey, bvalue) VALUES (1, 101.0);
INSERT INTO table_b (bkey, bvalue) VALUES (2, 102.0);
INSERT INTO table_b (bkey, bvalue) VALUES (4, 104.0);

UPDATE table_a SET avalue=(SELECT bvalue FROM table_b WHERE akey=bkey)
WHERE EXISTS(SELECT 1 FROM table_b WHERE akey=bkey);

I think there is no multi-table update idiom in SQLite because there
isn't one in SQL.

--David 

Robert Poor writes:
> 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
> [email protected]
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to