title: SQL: remove records with invalid foreign keys
body: <p>I just found a bug in my Rails app which would lead to certain records not getting deleted with their associated objects. The bug has been fixed, but I now have several thousand records in my database with foreign key values pointing to records that don't exist.</p>
  
  <p>Is it possible to delete all records in a table where an integer foreign key references a record in another table that doesn't exist in SQL? How?</p>