Delete main record that has no subrecords

M

mcdowdjr

I am having trouble running a delete query on the main records that
have no subrecords. Here is what I have. I have tblOrder with OrderID,
in a related tblTransaction I have all the items the customer orders in
detail. With a foreign key of OrderID. I am trying to run a delete
query that will delete the primary order record since it does not have
a matching transaction record. Thanks for any help..

-Josh
 
J

Jeff L

Delete from tblOrder
Where OrderId Not In (Select OrderID From tblTransaction)

Hope that helps!
 
G

Guest

In your delete query, add both tables and a join on the related column. Add
the OrderId column from tblTransaction and in the criteria for this, put:

Is Null

This should return records from the orders table that have no records in the
transaction table.

Barry
 
M

mcdowdjr

Thanks! That makes sense. However, I'm getting a syntax error with the
from clause.
 
M

mcdowdjr

Here is what I have put. It gives me a syntax error on the Tbl Order in
the first line.

DELETE FROM Order
WHERE NOT EXISTS (SELECT TransactionID FROM Transaction WHERE
Transaction.OrderID = Order.OrderID);

any help would be great, by the way I am using Access 2000 if that
makes a difference.
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top