Re: Removing Duplicates
- From: "Jeff Howard" <jhoward@xxxxxxxxxxxx>
- Date: Thu, 30 Mar 2006 15:08:32 -0700
I wish it were this straight forward and maybe I am making it to complicated
but I am trying to simply remove duplicates records coming in from a text
file based upon a composite key (Item number) and (pack type) so my
challange is that I need all the import text file information but I need to
remove the duplicates based upon only those two fields.
I am currently loading the import file into a temporary Access table then
using the join information that you provided me I am doing one sql statement
to update records in my Main Access table for those records that are a match
in the temporay Access table and then inserting new records that do not
exist in my Main Access table but do exist in the tempory Access table. At
some point I need to remove the duplicates based upon Item Number and Pack
Type. This is what my primary key is built upon for my Main Access table.
I am not very strong on my sql but so far this is what I am using assuming
that the import text file does not have any duplicates.
//load into temp access table
INSERT INTO [Temp_Import] ([User1],[Item Number],[Description],[Pack
Type],[Site Id],[User4]) SELECT [User1],[Item Num],[Description],[Pack
T],[Site ID1],[User4] FROM [TabDelimited.txt] IN "C:\Data\Delphi\Qbit\"
"Text;"
//update main access table records with info from temp access table
UPDATE [jeff] MT INNER JOIN Import.Temp_Import IT ON MT.[Item Number] =
IT.[Item Number] AND MT.[Pack Type] = IT.[Pack Type] SET MT.[User1] =
IT.[User1], MT.[Description] = IT.[Description], MT.[Site Id] = IT.[Site
Id], MT.[User4] = IT.[User4]
//insert new records into main access table where records do not exist in
temp access table
INSERT INTO [jeff] ([User1],[Item Number],[Description],[Pack Type],[Site
Id],[User4]) SELECT [User1],[Item Number],[Description],[Pack Type],[Site
Id],[User4] FROM Import.mdb.[Temp_Import] Import WHERE NOT EXISTS (SELECT
[Item Number], [Pack Type] FROM [jeff] WHERE [Item Number] = Import.[Item
Number] AND [Pack Type] = Import.[Pack Type])
"Brian Bushay TeamB" <BBushay@xxxxxxxxx> wrote in message
news:d9em22ttljj2k52m8bkfnkge2bvl4jbdr0@xxxxxxxxxx
What is the best way, using SQL, to remove duplicates from an Access
database?
If you have exact duplicate records do a
Select distinct * Into TempTable.
Then delete the contents of the original table and insert the records from
the
tempTable
--
Brian Bushay (TeamB)
Bbushay@xxxxxxxxx
.
- Follow-Ups:
- Re: Removing Duplicates
- From: Brian Bushay TeamB
- Re: Removing Duplicates
- From: John Herbster
- Re: Removing Duplicates
- References:
- Removing Duplicates
- From: Jeff Howard
- Re: Removing Duplicates
- From: Brian Bushay TeamB
- Removing Duplicates
- Prev by Date: How to connect a .net application to an Oracle RDB database???
- Next by Date: Re: Removing Duplicates
- Previous by thread: Re: Removing Duplicates
- Next by thread: Re: Removing Duplicates
- Index(es):
Relevant Pages
|