Removing extra WHERE in sql