Cannot delete from 1 side if no mathing on many side

S

Song

I try to delete agent (1 side) that has no matching record in master (many
side) but it would not allow me to do so. I can select, but not delete. Here
is my sql

DELETE tblAgent.*
FROM tblAgent LEFT JOIN tblMaster ON tblAgent.AgentID = tblMaster.AgentID
WHERE (((tblMaster.AgentID) Is Null));
 
K

Klatuu

This is untested, so make a copy, but I think this might do it:

DELETE * FROM tblAgent WHERE AgentID NOT IN(SELECT AgentID FROM tblMaster
WHERE AgentID IS NOT NULL);
 

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