Hi I know how to upload data from one table to another one:
INSERT INTO new_table (id, pricerange, rentrange, date)
SELECT id, price, rent, date
FROM initial_table
But I have a problem with this if you consider I have 10 rows in my initial table by this code I can upload all of them into new table and then after for example 10 hours if I have 10 new rows and I use this code in my new table I will have 30 rows. Because this code did not delete 10 old row and also add all 20 rows again. what can I do that not to upload first 10 row again?
Hey you can use this query
. This will insert
only those row
which are not present in first table
INSERT INTO new_table(id, pricerange, rentrange, date) SELECT id, price, rent, date FROM initial_table WHERE NOT EXISTS(SELECT * FROM new_table WHERE (initial_table.id=new_table.id))
You can add more condition
in if
statement if you want
Set a flag variable in the database. By default set the value as 0. If the data uploaded then set that value to 1. When you are upload one table to another check the flag value. Upload only those value which are 0.
Is there a primary key defined? Or if you can have a time stamp field / system change number on the table you can capture the scn / time stamp in a separate table after your first insert and get the records from base table by comparing the time stamp against the preserved one.