473,326 Members | 2,061 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.

Delete Query Question

I would like to create a delete query that consists of two tables linked
together. One table will be the target for the deletions while the other
table's equi-joins will tell the delete query which records in the target
table to delete. When you try to do this, an error message appears asking
you which table you want to delete records from (of the two tables shown in
the query). How do you tell Access what to do in this case???

Nov 12 '05 #1
5 4288
Try a subquery in the WHERE clause, e.g.:
DELETE FROM tblInvoice
WHERE tblInvoice.InvoiceID =
(SELECT InvoiceID FROM tblInvoiceDetail WHERE
tblInvoiceDetail.InvoiceDetailID = 9);

The example assumes cascading deletes.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mike Wiseley" <mi**********@gte.net> wrote in message
news:QV*****************@nwrddc02.gnilink.net...
I would like to create a delete query that consists of two tables linked
together. One table will be the target for the deletions while the other
table's equi-joins will tell the delete query which records in the target
table to delete. When you try to do this, an error message appears asking
you which table you want to delete records from (of the two tables shown in the query). How do you tell Access what to do in this case???

Nov 12 '05 #2
tom
I believe Access also lets you specify which table in your FROM clause
to delete from, like so (The "I.*" part):

DELETE I.*
FROM tblInvoice as I
INNER JOIN tblInvoiceDetail as D
On I.InvoiceID = D.InvoiceID
WHERE D.InvoiceDetailID = 9;

-td
Try a subquery in the WHERE clause, e.g.:
DELETE FROM tblInvoice
WHERE tblInvoice.InvoiceID =
(SELECT InvoiceID FROM tblInvoiceDetail WHERE
tblInvoiceDetail.InvoiceDetailID = 9);

Nov 12 '05 #3
I tried the following variation of your theme:

Delete * From Table1 Where Table1.[Departure Point] like
(SELECT Distinct cTable1.[Departure Point] FROM cTable1 inner join Table1 on
cTable1.[Departure Point] = Table1.[Departure point]);

Which was an attempt to delete multiple records from Table1 based on a match
against cTable1.
Access says "at most, one record can be returned from this subquery".
"tom" <to*@nuws.com> wrote in message
news:c1**************************@posting.google.c om...
I believe Access also lets you specify which table in your FROM clause
to delete from, like so (The "I.*" part):

DELETE I.*
FROM tblInvoice as I
INNER JOIN tblInvoiceDetail as D
On I.InvoiceID = D.InvoiceID
WHERE D.InvoiceDetailID = 9;

-td
Try a subquery in the WHERE clause, e.g.:
DELETE FROM tblInvoice
WHERE tblInvoice.InvoiceID =
(SELECT InvoiceID FROM tblInvoiceDetail WHERE
tblInvoiceDetail.InvoiceDetailID = 9);

Nov 12 '05 #4
Mike, if you are still stuck on this, would it be possible to use a Yes/No
field to flag the records for deletion? That's easy to do with an Update
query, and then the delete query is just:
DELETE FROM MyTable WHERE (IsPicked = True);

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mike Wiseley" <mi**********@gte.net> wrote in message
news:Z4****************@nwrddc02.gnilink.net...
I tried the following variation of your theme:

Delete * From Table1 Where Table1.[Departure Point] like
(SELECT Distinct cTable1.[Departure Point] FROM cTable1 inner join Table1 on cTable1.[Departure Point] = Table1.[Departure point]);

Which was an attempt to delete multiple records from Table1 based on a match against cTable1.
Access says "at most, one record can be returned from this subquery".
"tom" <to*@nuws.com> wrote in message
news:c1**************************@posting.google.c om...
I believe Access also lets you specify which table in your FROM clause
to delete from, like so (The "I.*" part):

DELETE I.*
FROM tblInvoice as I
INNER JOIN tblInvoiceDetail as D
On I.InvoiceID = D.InvoiceID
WHERE D.InvoiceDetailID = 9;

-td
Try a subquery in the WHERE clause, e.g.:
DELETE FROM tblInvoice
WHERE tblInvoice.InvoiceID =
(SELECT InvoiceID FROM tblInvoiceDetail WHERE
tblInvoiceDetail.InvoiceDetailID = 9);


Nov 12 '05 #5
That is in fact how I handle the situation at present. I was looking for an
alternate way of handling at the start of this thread.

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:40**********************@freenews.iinet.net.a u...
Mike, if you are still stuck on this, would it be possible to use a Yes/No
field to flag the records for deletion? That's easy to do with an Update
query, and then the delete query is just:
DELETE FROM MyTable WHERE (IsPicked = True);

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mike Wiseley" <mi**********@gte.net> wrote in message
news:Z4****************@nwrddc02.gnilink.net...
I tried the following variation of your theme:

Delete * From Table1 Where Table1.[Departure Point] like
(SELECT Distinct cTable1.[Departure Point] FROM cTable1 inner join
Table1 on
cTable1.[Departure Point] = Table1.[Departure point]);

Which was an attempt to delete multiple records from Table1 based on a

match
against cTable1.
Access says "at most, one record can be returned from this subquery".
"tom" <to*@nuws.com> wrote in message
news:c1**************************@posting.google.c om...
I believe Access also lets you specify which table in your FROM clause
to delete from, like so (The "I.*" part):

DELETE I.*
FROM tblInvoice as I
INNER JOIN tblInvoiceDetail as D
On I.InvoiceID = D.InvoiceID
WHERE D.InvoiceDetailID = 9;

-td

> Try a subquery in the WHERE clause, e.g.:
>
>
> DELETE FROM tblInvoice
> WHERE tblInvoice.InvoiceID =
> (SELECT InvoiceID FROM tblInvoiceDetail WHERE
> tblInvoiceDetail.InvoiceDetailID = 9);
>



Nov 12 '05 #6

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

Similar topics

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...
2
by: Dave Burt | last post by:
Hi, Access officionados, I'm new here, so please cut me slack/gently tell me off if I'm out of line or in the wrong place. OK, here's something that seems silly (and is also problematic to...
14
by: Karl O. Pinc | last post by:
Hi, Thought perhaps some other eyes than mine can tell if I'm doing something wrong here or if there's a bug somewhere. I've never passed a ROWTYPE varaible to a function but I don't see where...
4
by: Ignoramus6539 | last post by:
There were some strange requests to my server asking for config.php file (which I do not have in the requested location). I did some investigation. Seems to be a virus written in perl,...
17
by: (PeteCresswell) | last post by:
I've got apps where you *really* wouldn't want to delete certain items by accident, but the users just have to have a "Delete" button. My current strategies: Plan A:...
1
by: Matt | last post by:
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...
5
by: Bob Bridges | last post by:
Start with two tables, parent records in one and child records in the other, a one-to-many relationship. Create a select statement joining the two. Display the query in datasheet mode. When I...
3
by: jpatchak | last post by:
The following select query gives me the set of records I want to delete: SELECT tblCaseNumbers.* FROM (tblCaseNumberDump INNER JOIN ON tblCaseNumberDump.SSN = .) INNER JOIN tblCaseNumbers ON . =...
10
by: pythonnoob | last post by:
Hello everyone. New to python as well as this forum, but i must say ive learned a but already reading through some posts. Seems to be a pretty helpful community here. Before i post a question...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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.