By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,501 Members | 831 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,501 IT Pros & Developers. It's quick & easy.

Delete Query Question

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.