Dominique Pellé <dominique.pe...@gmail.com> wrote:
> For example, given 2 tables t1 and t2, both with 2 columns as follows...
> 
> Table t1:
> 
>    ID   name
>    --   ----
>    1    aaaa
>    2    NULL
>    3    NULL
>    4    bbbb
>    (~1 million records)
> 
> Table t2:
> 
>    ID   name
>    --   ----
>    2    XXXX
>    4    YYYY
>    (~500,000 records)
> 
> ... I would like to update the 'name' column in records of table t1, so that
> they are the same as the 'name' column in table t2 when the ID columns
> match.

update t1 set name = (select name from t2 where t1.ID=t2.ID)
where ID in (select ID from t2);

Or, if t1.ID is a primary key or otherwise has a unique constraint:

insert or replace into t1(ID, name)
select ID, name from t2;

-- 
Igor Tandetnik

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to