diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py
index f8171a4049d1ebd6168e548448ac45f4f37f8f83..ee478c4a0c55818ce3e78aec0d4580f0dd6ea864 100644
--- a/src/caosdb/common/models.py
+++ b/src/caosdb/common/models.py
@@ -4421,7 +4421,7 @@ class Query():
         query_dict["query"] = str(self.q)
 
         has_paging = False
-        is_count_query = self.q.lower().startswith('count')
+        is_count_query = self.q.split()[0].lower() == "count" if len(self.q.split()) > 0 else False
 
         if not unique and not is_count_query and page_length is not None and page_length > 0:
             has_paging = True
@@ -4434,9 +4434,7 @@ class Query():
         self.cached = cresp.query.cached
         self.etag = cresp.query.etag
 
-        if is_count_query and len(cresp) == 0:
-            # this was a count query
-
+        if is_count_query:
             return self.results
 
         if raise_exception_on_error: