Delete Query

gittymoe

Board Regular
Joined
Apr 23, 2005
Messages
79
Guys, I am trying to run a delete query that would identify records from an unmatched query and delete all these records from table CopyOfTblSVEPURCHASEORDERS. Below is what I have been trying without success. When I run this I receive the message of "The Specified Field '[PO No]' could refer to more than one table listed in the FROM clause of your SQL statement"

DELETE *
FROM CopyOfTblSVEPURCHASEORDERS
WHERE exists
(select 1
from CopyOfTblSVEPURCHASEORDERSWithoutMatchingSVEPurchaseOr
where [PO No] = CopyOfTblSVEPURCHASEORDERS.[PO No]);


Thanks for any help/advise.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
I would try fully qualifying [PO No] with CopyOfTblSVEPURCHASEORDERSWithoutMatchingSVEPurchaseOr.[PO No]
 
Upvote 0
Thanks, just to confirm, by qualifying you mean make these changes --where CopyOfTblSVEPURCHASEORDERSWithoutMatchingSVEPurchaseOr.[PO No]--? See revised code below. If this is correct, I am receiving a slightly different error message "The Specified Field CopyOfTblSVEPURCHASEORDERSWithoutMatchingSVEPurchaseOr.[PO No] could refer to more than one table listed in the FROM clause of your SQL statement"

DELETE *
FROM CopyOfTblSVEPURCHASEORDERS
WHERE exists
( select 1
from CopyOfTblSVEPURCHASEORDERSWithoutMatchingSVEPurchaseOr
where CopyOfTblSVEPURCHASEORDERSWithoutMatchingSVEPurchaseOr.[PO No] = CopyOfTblSVEPURCHASEORDERS.[PO No]);
 
Upvote 0
Yes, that's exactly what I meant. You also don't need the * in the DELETE statement, but I don't think that would cause your problem.

The format is:

DELETE FROM TableA
WHERE EXISTS (SELECT *
FROM TableB
WHERE TableB.ID1 = TableA.ID1)

...and that's what you have, so I don't know why it's not working. I will continue to investigate.
 
Upvote 0

Forum statistics

Threads
1,221,829
Messages
6,162,232
Members
451,756
Latest member
tommyw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top