nadavius <[email protected]> wrote:
> I have two tables T1, T2 - identical in fields [Index1 (INT), Index2(INT),
> Count(INT), Value(INT)]
> I would like to merge the content of T1 into T2 using the following ruels:
> 1. Copy into T2 data from T1 where Index1 AND Index2 (like two keys, PK and
> SK) do not exist in T2
> 2. In case that there are common rows between T1 and T2, where common means
> T1[Index1, Index2] and T2[Index1, Index2] are the same - update T2.Count and
> T2.Value ONLY IF T1.Count has a greater value
If there a unique index on T1(Index1, Index2), then something like this should
work:
insert or replace into T1
select T2.Index1, T2.Index2,
coalesce(alt.Count, T2.Count), coalesce(alt.Value, T2.Value)
from T2 left join T1 alt on
(T2.Index1=alt.Index1 and T2.Index2=alt.Index2 and alt.Count <= T2.Count);
--
Igor Tandetnik
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users