"Adam DeVita" <adev...@verifeye.com> wrote
in message
news:804081910903130900r6c615f02u2b72ba810cccf...@mail.gmail.com
> Suppose you have a field that time stamps the date each company's data
> was entered.
>
> Unfortunately some records in old2.db have newer contact information,
> while others are older than in old1.db.
>
> Since companies sometimes change their address the one with the latest
> 'date_Entered' should be the one left in the merged database.

Try something like this:

select * from old1 x where not exists (
    select 1 from old1 y
    where x.company = y.company and x.date_entered < y.date_entered)
and not exists (
    select 1 from old2 z
    where x.company = z.company and x.date_entered < z.date_entered);

insert into new
select * from old2 x where not exists (
    select 1 from old1 y
    where x.company = y.company and x.date_entered < y.date_entered)
and not exists (
    select 1 from old2 z
    where x.company = z.company and x.date_entered < z.date_entered);

Igor Tandetnik 



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

Reply via email to