473,326 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Trying to match records for a delete query

121 100+
I have a simple question but I have been pounding on it for a while and nothing will work.


I have two tables: [ERR_REC] and [STG_REC].

Basically, I want to delete any records from [ERR-REC] where the [REC_ID] in both tables match.

I have designed it so that i had a delete query of ERR_REC.* and the Where was [STG_REC].REC_ID. But every time I ran it it prompted me for [REC_ID].

I have designed it so that i had a delete query of ERR_REC.* and the Where was [ERR_REC]_REC_ID = [STG_REC].REC_ID. Also, every time I ran it it prompted me for [REC_ID].
Apr 16 '07 #1
6 1623
JHNielson
121 100+
As an update I also tried setting the criteria to:


Expand|Select|Wrap|Line Numbers
  1. DLookUp("[REC_ID]","[STG_REC]","[ERR_REC].[REC_ID]"="[STG_REC].[REC_ID]")
and it runs without an error, but is isn't actually deleting any records.
Apr 16 '07 #2
JHNielson
121 100+
Anyone have any ideas? I have racked my brain and can't figure out how to match these records?
Apr 16 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
Back up your tables (or database) first in case anything goes wrong. Then try the following query.
Expand|Select|Wrap|Line Numbers
  1. DELETE [ERR_REC].* 
  2. FROM [ERR_REC] LEFT JOIN [STG_REC]
  3. ON [ERR_REC].REC_ID=[STG_REC].REC_ID
  4. WHERE [STG_REC].REC_ID Is Not Null
Mary
Apr 16 '07 #4
JHNielson
121 100+
Back up your tables (or database) first in case anything goes wrong. Then try the following query.
Expand|Select|Wrap|Line Numbers
  1. DELETE [ERR_REC].* 
  2. FROM [ERR_REC] LEFT JOIN [STG_REC]
  3. ON [ERR_REC].REC_ID=[STG_REC].REC_ID
  4. WHERE [STG_REC].REC_ID Is Not Null
Mary

Fabulous - it worked like a charm
Apr 16 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
Fabulous - it worked like a charm
You're welcome.
Apr 16 '07 #6
NeoPa
32,556 Expert Mod 16PB
Fabulous - it worked like a charm
It certainly should work - It's perfect SQL for the task :)
Nice job Mary.
Apr 18 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: William Case | last post by:
I cannot believe I'm having this much trouble doing such a simple thing! I have two tables with identical structure. I can use an A2K select query to show the records in table 1 that match...
2
by: Joe Del Medico | last post by:
I have two tables A & B and I want to delete all the records in A that are not in B. Can I do this in the query builder? It seems like a simple problem. I can easily find the records in A that...
18
by: Gleep | last post by:
I've searched google intensely on this topic and it seems noone really knows how to approch this. The goal I don't want clients to give out their usernames and passwords to friends, since the site...
3
by: Jeff | last post by:
In a subform I have a simple SQL statement that links an order details table to a product table. The form is used to enter order details. Most fields are obviously from the details table, with only...
4
by: NancyJ | last post by:
Currently we have a database with a main table containing 3 million records - we want to increase that to 10 million but thats not a possibility at the moment. Nearly all 3 million records are...
2
by: Jim Devenish | last post by:
I have two tables: Deliveries and Invoices. An Invoice can relate to a number of Deliveries. The relevant fields are: Invoices: InvoiceID InvoiceDate Deliveries: DeliveryID
1
by: Shortstuff12345 | last post by:
This can be ignored... I did a bunch more searching and tried a few more things listed on different posts. I was able to get the delete query to work properly by adding a statement in the code...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
3
eclypz
by: eclypz | last post by:
Hi, i have read some posts of inner join and outer join, but no one could help me to solve my problem :( I have 2 tables 1) tblRecords (having, article; User;date in; date out; service) 2)...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.