Fix sql for autotag depending on whether a category is specified or not.