473,756 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deleting via a query with a join in it?

Seems to me like I've done this. When it wasn't possible to delete the records
in question via a fairly complicated query I resorted to creating a work table
containing IDs of recs TB deleted, then did the deletes by joining the target
table to the work table.

I'm trying to do that right now and an error's popping to the effect the delete
cannot be done.

Anybody know the rules?
--
PeteCresswell
Nov 12 '05 #1
5 1329
(Pete Cresswell) wrote:
Seems to me like I've done this. When it wasn't possible to delete
the records in question via a fairly complicated query I resorted to
creating a work table containing IDs of recs TB deleted, then did the
deletes by joining the target table to the work table.

I'm trying to do that right now and an error's popping to the effect
the delete cannot be done.

Anybody know the rules?


Did you try DISTINCTROW = query property "unique records"?

If that doesn't help you should post the SQL statement.

--
HTH
Karl
*********
Access-FAQ (German): http://www.donkarl.com
Nov 12 '05 #2
x@y.z ((Pete Cresswell)) wrote in
<kc************ *************** *****@4ax.com>:
Seems to me like I've done this. When it wasn't possible to
delete the records in question via a fairly complicated query I
resorted to creating a work table containing IDs of recs TB
deleted, then did the deletes by joining the target table to the
work table.

I'm trying to do that right now and an error's popping to the
effect the delete cannot be done.

Anybody know the rules?


What's the error?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #3
RE/
Did you try DISTINCTROW = query property "unique records"?


Bingo!

Thanks.
--
PeteCresswell
Nov 12 '05 #4
Pete,

without DDL or the SQL to see what's going on it hard to say. I too
have encountered the problem before.

It seems that if you are trying to delete a parent record (ie the 1
side of the relationship) from an attribute of a child (the N side);
you can't .

Works the other way though.

To get around this don't use a join, use

DELETE *
FROM Parent
WHERE PARENT_KEY
NOT IN(SELECT YourPK FROM child where attribute = value)

or somesuch derivative (NOT EXISTS may be quicker). Slower than a join
but does the trick and doesn't use temp tables.

Peter

"(Pete Cresswell)" <x@y.z> wrote in message news:<kc******* *************** **********@4ax. com>...
Seems to me like I've done this. When it wasn't possible to delete the records
in question via a fairly complicated query I resorted to creating a work table
containing IDs of recs TB deleted, then did the deletes by joining the target
table to the work table.

I'm trying to do that right now and an error's popping to the effect the delete
cannot be done.

Anybody know the rules?

Nov 12 '05 #5
RE/
To get around this don't use a join, use

DELETE *
FROM Parent
WHERE PARENT_KEY
NOT IN(SELECT YourPK FROM child where attribute = value)


That one's going into my "keepers" file....

As much as I've grown to love (and depend on) the graphical query builder, I can
see that it's exacted a price in my lack of familiarity with raw SQL.
--
PeteCresswell
Nov 12 '05 #6

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

Similar topics

0
3070
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me solve my problem. I'll turn to MySQL doc after getting through this pressing project. Thanks a lot Roger! Babale -----Urspr=FCngliche Nachricht-----
4
8670
by: XmlAdoNewbie | last post by:
Hi All, I am using Microsoft SQL Enterprise Manager version 8.0 and have created a view from a combination of 4 different tables. I would like to be able to go into sql and open the view and select a row and delete that row however this seem impossible right now. I am not sure if it's possible to delete a row from a view?? Or could it be that these tables are all interconnected and in order to delete a record that is joined to one or more...
1
6115
by: Mark | last post by:
This question refers to a main form with a continuous form subform. After an error occurs after entering several records in the subform, how can I delete all the data in the main form and all the records in the subform? I have tried undoing both the main form and the subform and I have tried deleting the record in the main form. Thanks! Mark
0
1734
by: ET | last post by:
We have two tables... one with primary key ID and second table with secondary key to the ID in the first table... Now, they query pulls records from both tables, looks like this: SELECT tblCell_Sat_Phone_Main.ID, tblCell_Sat_Phone_Main., tblCell_Sat_Phone_Main., tblCell_Sat_Phone_History.Location, tblCell_Sat_Phone_History.,
1
1946
by: koonda | last post by:
Hi all, Can somebody help me to find a solution for deleting some specific rows from 2 tables in one query. I can join the tables but I can't figure out how to delete some rows from both tables in the same query. Waiting for your answers. Thanks Koonda
1
1452
by: =?Utf-8?B?QW1pdA==?= | last post by:
I have an object datasource control that is referencing a class in the app code directory called SQLCommands.vb. That class calls stored procs in a remote server. On my page I'm using a GridView to update fields. I click edit, and edit some info, then click update and it calls the right update function. It executes the query with no exceptions and when the page refreshes the row disappears! Anyone experience anything like this? ...
11
16329
by: funky | last post by:
hello, I've got a big problem ad i'm not able to resolve it. We have a server running oracle 10g version 10.1.0. We usually use access as front end and connect database tables for data extraction. We have been using oracle client 10.1.0.2 with it's odbc for a while without problem. The problem arose when we decided to reconnect all the tables and save password. Some query became suddenly very slow. Then I've discovered that the tables...
13
2465
by: programming | last post by:
how do i delete from a text file 1 of the following lines: jon|scott adam|smith <--delete paul|clark say i would like to delete the middle line of this txt, in member.txt what php code or logic would help me accomplish this?
2
9840
by: existential.philosophy | last post by:
This is a new problem for me: I have some queries that open very slowly in design view. My benchmark query takes about 20 minutes to open in design view. That same query takes about 20 minutes to open in datasheet view. As an experiment, I deleted all rows in all tables; after that, the query took only seconds to open in both design view and datasheet view. From these facts, I conclude that Access is evaluating the query when I go to...
0
9255
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9819
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9689
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
8688
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
7226
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
6514
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5289
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3326
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2647
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.