Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT record if doesn't exist in other table 1

Status
Not open for further replies.

cuetzpalin

Programmer
Jun 5, 2002
99
US
Hi,

I have a table that contains "daily" data and another table containing "historical" data.

I need to insert the "daily" data into the "historical" data but I don't want any duplicates added to the "historical" table if the "daily" record already exists.

Can you please provide the INSERT statement to accomplish this? Thanks!
 
Hi,
Try this from Ask Tom (
AskTom said:
How can the Merge functionality be implemented in 8.1.7?



Followup June 1, 2004 - 4pm US/Eastern:

takes two steps

update ( select table_merging_into_columns (eg: existing table),
table_containing_updates_columns
from table_merging_into, table_containing_updates
where ... )
set table_merging_into_columns = table_containing_updates_columns
/

insert into table_merging_into
select *
from table_containing_updates
where (primary_key) NOT IN ( select primary_key from table_merging_into);

[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Or
Code:
INSERT INTO historical_table
(SELECT * FROM daily_table
 MINUS
 SELECT * FROM historical_table);
Of course, this assumes the two tables have identical structures.
 
Hi,
Great idea carp, that should work a treat assuming the structures match - a star for you for coming up with an elegantly simple solution.

[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Thanks, Turkbear. If you want a simple solution, ask a simple person. If you want an efficient solution, ask a lazy person. I can fill both squares!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top