ferrety ferrety <[EMAIL PROTECTED]>
wrote:
> Let me give you how the DBs looks like in a real example.
> Each DB contains a uniq table called URL :
>
> CREATE TABLE if not exists URL (name VARCHAR PRIMARY KEY, nbr
> INTEGER);
>
> $ sqlite3 /tmp/links1.db :
> sqlite> select * from URL;
> www.foo.com|17
> www.bar.com|100
> www.lost.com|5
>
> $ sqlite3 /tmp/links2.db :
> sqlite> select * from URL;
> www.lost.com|22
> www.bar.com|9
> www.dharma.com|1
>
> The objective is to merge these 2 DBs in the first one
> "/tmp/links1.db" to get this:
> $ sqlite3 /tmp/links1.db :
> sqlite> select * from URL;
> www.foo.com|17
> www.lost.com|27
> www.bar.com|109
> www.dharma.com|1

Perhaps something like this:

$ sqlite3 /tmp/links1.db
attach '/tmp/links2.db' as second;

insert or replace into main.URL(name, nbr)
select u2.name, u2.nbr + coalesce(u1.nbr, 0)
from second.URL u2 left join main.URL u1 on (u2.name=u1.name);


Igor Tandetnik



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

Reply via email to