473,490 Members | 2,472 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

SQL Delete doesn't work in query window but does in code...

I want to delete records from the "one" table of a one to may relationship.
There are no actual Access relationships set up. The "one" table has a
single field PK and the "many" table has a two field PK. This code works
when executed from a module (both DAO and ADO work), but not from the query
window.

DELETE a1.*, a2.Field1
FROM a1 LEFT JOIN a2 ON a1.Field1 = a2.Field1
WHERE (((a2.Field1) Is Null));

I know I could use a subquery, but why doesn't it work from the query window
and how do I get ti to work?

Thanks.

Matthew Wells

MW****@NumberCruncher.com


Nov 12 '05 #1
2 2288
"Matthew Wells" <MW****@NumberCruncher.com> wrote in message
news:wB******************@bignews4.bellsouth.net.. .
I want to delete records from the "one" table of a one to may relationship. There are no actual Access relationships set up. The "one" table has a
single field PK and the "many" table has a two field PK. This code works
when executed from a module (both DAO and ADO work), but not from the query window.

DELETE a1.*, a2.Field1
FROM a1 LEFT JOIN a2 ON a1.Field1 = a2.Field1
WHERE (((a2.Field1) Is Null));

I know I could use a subquery, but why doesn't it work from the query window and how do I get ti to work?

Thanks.

Matthew Wells

MW****@NumberCruncher.com

If you are determined not to use a sub-query, then you could add DISTINCTROW
as shown below. However, this is not supported by other database products
and the sub-query would make your SQL more portable.

DELETE DISTINCTROW a1.*
FROM a1 LEFT JOIN a2 ON a1.Field1=a2.Field1
WHERE a2.Field1 Is Null

Preferred solution from previous post:

DELETE FROM a1 WHERE a1.Field1
NOT IN (SELECT a2.Field1 FROM a2)
Now, as to why your first statement works in code (which indeed it does) but
not from the query window - I don't know. Perhaps someone can offer a
detailed explanation as a point of technical curiosity, but I would prefer
to simply accept a form of SQL which is unambiguous, portable and works in
code or from the Db window.

Fletcher
Nov 12 '05 #2
I don't want to delete a2.field1, I want to delete records in a1 that don't
have a corresponding a2 record. The a2Field1 is there for the WHERE cluese
(WHERE a2.fieldd1 Is Null). Also, the example I gave is much simpler than
what I'm really doing because my a1 table has a 3 field pk and my a2 table
has a 7 field pk. I don't think there's a way to write a subquery when
there's more than one field in the a1 pk.

"Chuck Grimsby" <c.*******@worldnet.att.net.invalid> wrote in message
news:8a********************************@4ax.com...

Uh, why do you want to delete the a2.Field1 ?
DELETE a1.*, a2.Field1


should be:
DELETE a1.*

On Mon, 26 Jan 2004 09:33:13 -0500, "Matthew Wells"
<MW****@NumberCruncher.com> wrote:
I want to delete records from the "one" table of a one to may relationship.There are no actual Access relationships set up. The "one" table has a
single field PK and the "many" table has a two field PK. This code works
when executed from a module (both DAO and ADO work), but not from the querywindow.

DELETE a1.*, a2.Field1
FROM a1 LEFT JOIN a2 ON a1.Field1 = a2.Field1
WHERE (((a2.Field1) Is Null));

I know I could use a subquery, but why doesn't it work from the query windowand how do I get ti to work?

Thanks.

Matthew Wells

MW****@NumberCruncher.com


Nov 12 '05 #3

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

Similar topics

1
1300
by: Matthew Wells | last post by:
I want to delete records from the "one" table of a one to may relationship. There are no actual Access relationships set up. The "one" table has a single field PK and the "many" table has a two...
1
2819
by: Matthew Wells | last post by:
I want to delete records from the "one" table of a one to may relationship. There are no actual Access relationships set up. The "one" table has a single field PK and the "many" table has a two...
5
1777
by: ms | last post by:
Why does this select query return the correct records but when I make it a delete query I get a msgbox with "Could not delete from specified tables". SELECT BMIDLog.* FROM stageBMIDLog INNER...
3
3792
by: Kevin M | last post by:
I have one table and have created a form from that table. Also, I have created a delete query. I want to but a button on the form which will delete all records from the table; however, I cannot get...
0
6974
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...
0
7146
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7183
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...
1
6852
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...
0
7356
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...
0
5448
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,...
1
4878
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...
0
3084
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...
0
1389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.