472,799 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

DELETE Statement question

I am writing a DELETE statement and I want to filter the records using
another SELECT statement.

My SELECT statement is a GROUP BY query that grabs all social security
numbers from the "Data With Import Date Current" table on a given day
where there was only one transaction (count of SSN = 1). I want to
delete these records from the "Data With Import Date Current" table.
I would like to do this by joining the "Data With Import Date Current"
table to the SELECT statement in a delete query (joining on date and
SSN), but I get an error "Could Not Delete From The Specified Table"
when I try this. So to get around it I used a sub query. This takes
FOREVER and I was wondering if there was a way I could join these 2
queries in a delete query so it runs faster.
Here is my SQL (The one that is giving me the error):
---------------------------------------------------------------------------*------------------------------

DELETE [Data With Import Date Current].*
FROM qryDateSSNSingleContract INNER JOIN [Data With Import Date
Current] ON (qryDateSSNSingleContract.[Owner SSN] = [Data With Import
Date Current].[Owner SSN]) AND (qryDateSSNSingleContract.[Transaction
Date] = [Data With Import Date Current].[Transaction Date]);
---------------------------------------------------------------------------*-------------------------------

As always, thanks in advance!

Jan 21 '07 #1
1 3556

Matt wrote:
I am writing a DELETE statement and I want to filter the records using
another SELECT statement.

My SELECT statement is a GROUP BY query that grabs all social security
numbers from the "Data With Import Date Current" table on a given day
where there was only one transaction (count of SSN = 1). I want to
delete these records from the "Data With Import Date Current" table.
I would like to do this by joining the "Data With Import Date Current"
table to the SELECT statement in a delete query (joining on date and
SSN), but I get an error "Could Not Delete From The Specified Table"
when I try this. So to get around it I used a sub query. This takes
FOREVER and I was wondering if there was a way I could join these 2
queries in a delete query so it runs faster.
Here is my SQL (The one that is giving me the error):
---------------------------------------------------------------------------*------------------------------

DELETE [Data With Import Date Current].*
FROM qryDateSSNSingleContract INNER JOIN [Data With Import Date
Current] ON (qryDateSSNSingleContract.[Owner SSN] = [Data With Import
Date Current].[Owner SSN]) AND (qryDateSSNSingleContract.[Transaction
Date] = [Data With Import Date Current].[Transaction Date]);
---------------------------------------------------------------------------*-------------------------------
DELETE and UPDATE queries must be run against "updateable" recordsets.
When you join your table to the aggregate (GROUP BY) query the
resultant recordset is not "updateable" and your delete fails even
though you are not trying to delete anything from the query.

So, you either need to use a subquery, something like this (untested)
DELETE [Data With Import Date Current].*
FROM [Data With Import Date Current]
WHERE EXISTS (
SELECT qryDateSSNSingleContract.[Owner SSN],
qryDateSSNSingleContract.[Transaction Date]
WHERE (qryDateSSNSingleContract.[Owner SSN]
= [Data With Import Date Current].[Owner SSN])
AND (qryDateSSNSingleContract.[Transaction Date]
= [Data With Import Date Current].[Transaction Date])
);
or send the results of your aggregate query to a temporary table and
then use that table for your join in the DELETE query, i.e.
SELECT qryDateSSNSingleContract.* INTO zzz_temp_tbl
FROM qryDateSSNSingleContract;

DELETE [Data With Import Date Current].*
FROM zzz_temp_tbl INNER JOIN [Data With Import Date
Current] ON (zzz_temp_tbl.[Owner SSN] = [Data With Import
Date Current].[Owner SSN]) AND (zzz_temp_tbl.[Transaction
Date] = [Data With Import Date Current].[Transaction Date]);

Jan 21 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

52
by: Newsnet Customer | last post by:
Hi, Statement 1: "A dynamically created local object will call it's destructor method when it goes out of scope when a procedure returms" Agree. Statement 2: "A dynamically created object...
1
by: Matik | last post by:
Hello to all, I have a small question. I call the SP outer the DB. The procedure deletes some record in table T1. The table T1 has a trigger after delete. This is very importand for me, that...
4
by: Stefan Strasser | last post by:
why is delete an expression and not a statement? (in my draft copy of the standard). I was about to ask the same question about "throw" but found an expression case of throw("return boolvalue ? 5...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
12
by: yufufi | last post by:
Hello, How does delete know how much memory to deallocate from the given pointer? AFAIK this informations is put there by new. new puts the size of the allocated memory before the just before...
29
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I remembered delete is implemented through operator overloading, but I am not quite clear. Could anyone recommend some links about how delete is implemented so that I can...
18
by: aj | last post by:
I have the following snippet of code. On some platforms, the delete calls works, on Linux, it core dumps (memory dump) at the delete call. Am I responsible for deleting the memory that...
8
by: Michel Esber | last post by:
Hello, Env: DB2 V8 LUW FP16 running Linux create Table X (machine_id varchar(24) not null, ctime timestamp not null); create index iFoo on X (MACHINE_ID, CTIME) allow reverse scans; alter...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.