Importing existing data from another table

  • Thread starter Thread starter giannis
  • Start date Start date
G

giannis

I have make a query that imports data in a table
from another table.
What must write in the WHERE in order that dont
import records that exist in the target table ?

The query is (withot WHERE) :

INSERT INTO Table1 ( field1, field2 )
SELECT [Table2].[F1], [Table2].[F2]
FROM Data WHERE ............
 
....sorry the word "Data" is wrong.
The query is (without WHERE) :

INSERT INTO Table1 ( field1, field2 )
SELECT [Table2].[F1], [Table2].[F2]
FROM Table2 WHERE ............

What must write in the WHRE in order
the identical records dont importing ?
 
If the primary key is the same in both tables, you would not need to worry
about it because it would toss out any records that are dups because of key
field duplication. Doesn't sound like that is the case or you probably
wouldn't be asking the question.

One method would be to setup your main table to have a multiple field
primary that consists of enough of your main fields that, combined, would
throw an error when a duplicate is attempting to be added.

A preferable way would be to use code to iterate through each record in the
import table and using enough info from that record to examine the master
table for a dup. If none is found, append the record, otherwise skip it.

Gary Miller
 
I need write the WHERE in the SQL clouse.....

Gary Miller said:
If the primary key is the same in both tables, you would not need to worry
about it because it would toss out any records that are dups because of key
field duplication. Doesn't sound like that is the case or you probably
wouldn't be asking the question.

One method would be to setup your main table to have a multiple field
primary that consists of enough of your main fields that, combined, would
throw an error when a duplicate is attempting to be added.

A preferable way would be to use code to iterate through each record in the
import table and using enough info from that record to examine the master
table for a dup. If none is found, append the record, otherwise skip it.

Gary Miller



giannis said:
I have make a query that imports data in a table
from another table.
What must write in the WHERE in order that dont
import records that exist in the target table ?

The query is (withot WHERE) :

INSERT INTO Table1 ( field1, field2 )
SELECT [Table2].[F1], [Table2].[F2]
FROM Data WHERE ............
 
Well, don't do it there. Do it in the JOIN clause:

INSERT INTO targettable
SELECT ....
FROM sourcetable LEFT JOIN targettable
ON sourcetable.ID = targettable.ID
WHERE Targettable.ID IS NULL;
 
This Clouse dont running !!!
What is the ID ?

John Vinson said:
Well, don't do it there. Do it in the JOIN clause:

INSERT INTO targettable
SELECT ....
FROM sourcetable LEFT JOIN targettable
ON sourcetable.ID = targettable.ID
WHERE Targettable.ID IS NULL;
 
This Clouse dont running !!!
What is the ID ?

I don't know what the name of the primary key is in your table; my
telepathy is not functioning very well today. I was using it as AN
EXAMPLE of how you would write the query. Change the name of the field
ID to the appropriate linking field in *your* table - you know what
that is; I don't.
 
Back
Top