Fix problem with joins in delete command and update unit test