Delete Records from Table using Query Results

S

SITCFanTN

I have a table named "Records" that contains a field "Customer Number". I
need to delete all the records in table "Records" if the "Customer Number" is
also in the table named "Transfer". Is there a simple way to accomplish
this? Thank you!
 
J

John Spencer

Use a delete query

DELETE
FROM Records
WHERE [Customer Number] in
(SELECT [Customer Number] FROM Transfer)

In query design view
== Add the table Records
== Select the customer number into the list of fields
== Select Query: Delete from the menu
== Enter the criteria under the customer number field
in (SELECT [Customer Number] FROM Transfer)

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 
S

SITCFanTN

Hi John,

When I use the delete query you gave me, all the records I have in table
named "Records" are deleted. I just need the records deleted that contains a
duplicate "Customer Number" in the table "Records" and that also appear in
table "Transfer". Do you have any idea what I could be doing wrong. I'm
using exactly what you gave me below. As always I appreciate your help,
thank you.

John Spencer said:
Use a delete query

DELETE
FROM Records
WHERE [Customer Number] in
(SELECT [Customer Number] FROM Transfer)

In query design view
== Add the table Records
== Select the customer number into the list of fields
== Select Query: Delete from the menu
== Enter the criteria under the customer number field
in (SELECT [Customer Number] FROM Transfer)

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
I have a table named "Records" that contains a field "Customer Number". I
need to delete all the records in table "Records" if the "Customer Number" is
also in the table named "Transfer". Is there a simple way to accomplish
this? Thank you!
.
 
J

John Spencer

That indicates to me that the table Transfer contains all the customer numbers
that are in the table Records. If that is the case you need a way to delete
just the duplicates.

The next step is to determine which records in the Records table you want to
keep. If you have several records with the Customer Number 12345, what
criteria would you use to determine which record to retain? Or does it matter
which record you retain?

There are several techniques that can be used depending on the design of your
database and what relationships (if any) are defined that involve the Records
table.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
Hi John,

When I use the delete query you gave me, all the records I have in table
named "Records" are deleted. I just need the records deleted that contains a
duplicate "Customer Number" in the table "Records" and that also appear in
table "Transfer". Do you have any idea what I could be doing wrong. I'm
using exactly what you gave me below. As always I appreciate your help,
thank you.

John Spencer said:
Use a delete query

DELETE
FROM Records
WHERE [Customer Number] in
(SELECT [Customer Number] FROM Transfer)

In query design view
== Add the table Records
== Select the customer number into the list of fields
== Select Query: Delete from the menu
== Enter the criteria under the customer number field
in (SELECT [Customer Number] FROM Transfer)

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
I have a table named "Records" that contains a field "Customer Number". I
need to delete all the records in table "Records" if the "Customer Number" is
also in the table named "Transfer". Is there a simple way to accomplish
this? Thank you!
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top