Finding orphaned files

Public

SQL query which returns you a list of files which aren't assigned to any node. Use with care! Source: http://drupal.org/node/733258#comment-7076002

Get raw version
sql
  1. SELECT fm.*
  2. FROM file_managed AS fm
  3. LEFT OUTER JOIN file_usage AS fu ON ( fm.fid = fu.fid )
  4. LEFT OUTER JOIN node AS n ON ( fu.id = n.nid )
  5. WHERE (fu.TYPE = 'node' OR fu.TYPE IS NULL) AND n.nid IS NULL