Fixed spme sql statements where table and join statements were missing.