473,806 Members | 2,583 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4314
Try a subquery in the WHERE clause, e.g.:
DELETE FROM tblInvoice
WHERE tblInvoice.Invo iceID =
(SELECT InvoiceID FROM tblInvoiceDetai l WHERE
tblInvoiceDetai l.InvoiceDetail ID = 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**********@g te.net> wrote in message
news:QV******** *********@nwrdd c02.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 tblInvoiceDetai l as D
On I.InvoiceID = D.InvoiceID
WHERE D.InvoiceDetail ID = 9;

-td
Try a subquery in the WHERE clause, e.g.:
DELETE FROM tblInvoice
WHERE tblInvoice.Invo iceID =
(SELECT InvoiceID FROM tblInvoiceDetai l WHERE
tblInvoiceDetai l.InvoiceDetail ID = 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.goo gle.com...
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 tblInvoiceDetai l as D
On I.InvoiceID = D.InvoiceID
WHERE D.InvoiceDetail ID = 9;

-td
Try a subquery in the WHERE clause, e.g.:
DELETE FROM tblInvoice
WHERE tblInvoice.Invo iceID =
(SELECT InvoiceID FROM tblInvoiceDetai l WHERE
tblInvoiceDetai l.InvoiceDetail ID = 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**********@g te.net> wrote in message
news:Z4******** ********@nwrddc 02.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.goo gle.com...
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 tblInvoiceDetai l as D
On I.InvoiceID = D.InvoiceID
WHERE D.InvoiceDetail ID = 9;

-td
Try a subquery in the WHERE clause, e.g.:
DELETE FROM tblInvoice
WHERE tblInvoice.Invo iceID =
(SELECT InvoiceID FROM tblInvoiceDetai l WHERE
tblInvoiceDetai l.InvoiceDetail ID = 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*********@Se eSig.Invalid> wrote in message
news:40******** **************@ freenews.iinet. net.au...
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**********@g te.net> wrote in message
news:Z4******** ********@nwrddc 02.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.goo gle.com...
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 tblInvoiceDetai l as D
On I.InvoiceID = D.InvoiceID
WHERE D.InvoiceDetail ID = 9;

-td

> Try a subquery in the WHERE clause, e.g.:
>
>
> DELETE FROM tblInvoice
> WHERE tblInvoice.Invo iceID =
> (SELECT InvoiceID FROM tblInvoiceDetai l WHERE
> tblInvoiceDetai l.InvoiceDetail ID = 9);
>



Nov 12 '05 #6

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

Similar topics

16
3881
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 table, or perhaps bytes, being updated where the engine just decides, screw it, i'll just make a new one. surfed this group and google, but couldn't find anything. the context: we have some java folk who like to parametize/
2
2584
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 me). I have a query which is updateable when viewed as a datasheet in Access (you can insert, delete, update). Using queries, I can insert and update, but not delete.
14
5840
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 the problem is. I keep getting errors like (the first is my debug output): NOTICE: last cycle is: 11 WARNING: Error occurred while executing PL/pgSQL function
4
10633
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, exploiting a vulnerability in php code. The requests are like this 216.120.231.252 - - "GET /algebra/about/history/config.php?returnpath=http://domates.1gig.biz/spread.txt? HTTP/1.1" 404 561 "-" "libwww-perl/5.805"
17
2075
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) Make the cmd button black and do not give it an accelerator key. 2) Issue two levels of confirmation (Do you want to delete... Do you REALLY want
1
3629
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 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...
5
4149
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 delete a row, only the child record is deleted from the source tables; the parent record is still there...which is what I wanted. Now display fields from that query in a continuous form. When I delete a record from that form, one of the child...
3
1788
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 . = tblCaseNumbers.ProspectKey WHERE ((=IIf(Right(,1)='D','D',IIf(Right(,1)='A','PLP', IIf(Right(,1)='B','SLP','M'))))); When I try to make it a delete query however: DELETE tblCaseNumbers.* FROM (tblCaseNumberDump INNER JOIN ON...
10
2068
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 ill give you a little background. I have done programming in the past in Basic, VB, and a little C. I am not much of a programmer, its more of a hobby/curiosity. The following code is not mine, i am trying to modify a template of a mock database....
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10111
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9192
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5683
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3852
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3010
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.