Updated query to fix errors

mostly changing db table names