Remove unused table in query