Fix for error "Cannot combine unique query with non-unique query"