"illias" <[EMAIL PROTECTED]> writes:
> how to sync two tables in sqlite..
> ...
> in synchorinze table i import new items which not exist in
> production table but also items
> which price is changed and alredy exist in production table.
>
It's unclear whether you want the maximum price from the two tables, or always
the price from second table. In the former case, you can do something like
this:
SQLite version 2.8.15
Enter ".help" for instructions
sqlite> create table t1 (id integer primary key, name text, price float);
sqlite> create table t2 (id integer primary key, name text, price float);
sqlite> insert into t1 values (1, 'Item1', 110);
sqlite> insert into t1 values (2, 'Item2', 120);
sqlite> insert into t1 values (3, 'Item3', 130);
sqlite> insert into t1 values (4, 'Item4', 140);
sqlite> insert into t1 values (5, 'Item5', 150);
sqlite> insert into t1 values (6, 'Item6', 160);
sqlite> insert into t2 values (1, 'Item1', 199);
sqlite> insert into t2 values (2, 'Item2', 220);
sqlite> insert into t2 values (7, 'Item7', 170);
sqlite> select id, max(price) from
...> (select id, price from t1
...> union
...> select id, price from t2)
...> group by id
...> order by id;
id = 1
max(price) = 199
id = 2
max(price) = 220
id = 3
max(price) = 130
id = 4
max(price) = 140
id = 5
max(price) = 150
id = 6
max(price) = 160
id = 7
max(price) = 170
sqlite>
In the latter case, this should do what you want:
sqlite> insert or replace into t1 select * from t2;
sqlite> select id, price from t1;
id = 1
price = 199
id = 2
price = 220
id = 3
price = 130
id = 4
price = 140
id = 5
price = 150
id = 6
price = 160
id = 7
price = 170
sqlite>
Note that either 'id' or 'name must be defined as PRIMARY KEY for this to
work. Also, for the former case, i'll be a lot easier if you get rid of the
currency mark in your prices.
Derrell