Deleted files for node are being included in view for services We are using the services module to provide a JSON feed for our internal portal to pick up our articles. The page view that provides all files for each node uses the File Usage: Content relationship. We just noticed that even files that have been deleted from the node are still being listed.

The query that views shows (when I take that same view and set as a block) 

SELECT file_managed.uri AS file_managed_uri, file_managed.fid AS fid, file_managed.filemime AS file_managed_filemime, users_file_managed.mail AS users_file_managed_mail, 'file' AS field_data_field_caption_file_entity_type, 'file' AS field_data_field_file_image_alt_text_file_entity_type, 'file' AS field_data_field_file_image_title_text_file_entity_type
FROM 
{file_managed} file_managed
LEFT JOIN {file_usage} file_usage ON file_managed.fid = file_usage.fid
INNER JOIN {node} node_file_usage ON file_usage.id = node_file_usage.nid AND file_usage.type = 'node'
LEFT JOIN {users} users_file_managed ON file_managed.uid = users_file_managed.uid
WHERE (( (node_file_usage.nid = '') ))

The nid is provided as a parameter.

How can I get it to not include files that were removed from the node?
You should use file_usage_delete to remove file usage records to nodes that files was having relations so you stop that problem for future deleting files on nodes.

And you still have to fix it for the existing nodes I suggest two ways

first : write a script to loop on file_usage records and check if the not currently used in the node (via node load and check fid exist) if so delete that record (if u have small number of rows in that table)

secod : Implement hook_views_pre_render  and do the same check.

the first is preferred however it may take long time but it will stop the problem reason