diff --git a/scope.go b/scope.go index 2b9b21e7..48a87f58 100644 --- a/scope.go +++ b/scope.go @@ -917,7 +917,9 @@ func (scope *Scope) pluck(column string, value interface{}) *Scope { } func (scope *Scope) count(value interface{}) *Scope { - scope.Search.Select("count(*)") + if query, ok := scope.Search.selects["query"]; !ok || !strings.Contains(fmt.Sprint(query), "count(") { + scope.Search.Select("count(*)") + } scope.Search.countingQuery = true scope.Err(scope.row().Scan(value)) return scope