diff --git a/core/modules/views/src/Plugin/views/query/Sql.php b/core/modules/views/src/Plugin/views/query/Sql.php
index ae00eac454659bc3380630843bbb037d701b1b2f..035df8b59380d383b2daea19f0e729de854a526f 100644
--- a/core/modules/views/src/Plugin/views/query/Sql.php
+++ b/core/modules/views/src/Plugin/views/query/Sql.php
@@ -1357,7 +1357,7 @@ public function query($get_count = FALSE) {
     $entity_information = $this->getEntityTableInfo();
     if ($entity_information) {
       $params = [];
-      if ($groupby) {
+      if ($this->hasAggregate) {
         // Handle grouping, by retrieving the minimum entity_id.
         $params = [
           'function' => 'min',
diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_aggregate_count_function.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_aggregate_count_function.yml
new file mode 100644
index 0000000000000000000000000000000000000000..1bd8840dfd6d301453d4568cb525f4b8440bb635
--- /dev/null
+++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_aggregate_count_function.yml
@@ -0,0 +1,55 @@
+langcode: en
+status: true
+dependencies: {  }
+id: test_aggregate_count_function
+label: ''
+module: views
+description: ''
+tag: ''
+base_table: entity_test
+base_field: id
+display:
+  default:
+    display_options:
+      access:
+        type: none
+      arguments: { }
+      cache:
+        type: tag
+      exposed_form:
+        type: basic
+      fields:
+        id:
+          alter:
+            alter_text: false
+            ellipsis: true
+            html: false
+            make_link: false
+            strip_tags: false
+            trim: false
+            word_boundary: true
+          empty_zero: false
+          field: id
+          group_type: count
+          hide_empty: false
+          id: id
+          table: entity_test
+          plugin_id: field
+          type: number_integer
+          entity_type: entity_test
+          entity_field: id
+      group_by: true
+      pager:
+        type: some
+      query:
+        options:
+          query_comment: ''
+        type: views_query
+      style:
+        type: default
+      row:
+        type: fields
+    display_plugin: default
+    display_title: Default
+    id: default
+    position: 0
diff --git a/core/modules/views/tests/src/Kernel/QueryGroupByTest.php b/core/modules/views/tests/src/Kernel/QueryGroupByTest.php
index 62be526db265a3da4ae0f6bd3ade2ca5f4aee4f9..171688321e4ea53d6238bc96f17d8bacccec755a 100644
--- a/core/modules/views/tests/src/Kernel/QueryGroupByTest.php
+++ b/core/modules/views/tests/src/Kernel/QueryGroupByTest.php
@@ -21,7 +21,14 @@ class QueryGroupByTest extends ViewsKernelTestBase {
    *
    * @var array
    */
-  public static $testViews = ['test_group_by_in_filters', 'test_aggregate_count', 'test_group_by_count', 'test_group_by_count_multicardinality', 'test_group_by_field_not_within_bundle'];
+  public static $testViews = [
+    'test_group_by_in_filters',
+    'test_aggregate_count',
+    'test_aggregate_count_function',
+    'test_group_by_count',
+    'test_group_by_count_multicardinality',
+    'test_group_by_field_not_within_bundle',
+  ];
 
   /**
    * Modules to enable.
@@ -79,6 +86,19 @@ public function testAggregateCount() {
     $this->assertEquals(3, $types['name2']);
   }
 
+  /**
+   * Tests aggregate count feature with no group by.
+   */
+  public function testAggregateCountFunction() {
+    $this->setupTestEntities();
+
+    $view = Views::getView('test_aggregate_count_function');
+    $this->executeView($view);
+
+    $this->assertEquals(7, $view->result[0]->id);
+    $this->assertCount(1, $view->result, 'Make sure the count of rows is one.');
+  }
+
   /**
    * Provides a test helper which runs a view with some aggregation function.
    *