I have 2 SQL tables as follows:
create table dbo.Posts (
Id int identity not null,
Content nvarchar (max) not null
-- other columns
)
create table dbo.Files (
Id int identity not null,
Name nvarchar (200) not null
-- other columns
)
I need to delete all files where its Name does not appear inside the Content column of any Post ... Note, that Content has HTML code where the files Names are somewhere included.
For example, if File with Name=hello-john
is not found in Content of any Post then it should be deleted.
UPDATE
I tried a Select to test it but somehow this gives me all files so I am not sure what am I missing:
select Name
from dbo.Files
where Name NOT IN (SELECT p.Content FROM dbo.Posts as p)
Am I missing something?