I have a table which is called Document
.
Document:
id int
docuid int
doc blob
Then I have two referencing tables
AppRequiredDocuments:
id int
appid int
docid int -> references document -> id
AppDocuments:
id int
appid int
docid int -> references document -> id
I have due to an very old migration orphaned items in the document table which have to references in the other tables. How can I delete only the documents in the document table which are not referenced in AppDocuments
or AppRequriedDocuments
?
You can use
NOT EXISTS
to find and delete those items: