EntityQuery group by clause Using the EntityQuery API I am trying to add a group by clause to the query, however, it doesn't seem that one exists.  The EntityQuery API does not have a groupBy() method.

Current Code:

$nodes = Drupal::entityQuery('node')
    -&gt;condition('type', 'thing')
    -&gt;condition('field_num_1', 'value', '=')
    -&gt;condition('field_num_2', 'value', '=')
    -&gt;range(0, 10)
    -&gt;sort('title', 'ASC')
    -&gt;execute();


Ideal Code:

$nodes = Drupal::entityQuery('node')
    -&gt;condition('type', 'thing')
    -&gt;condition('field_num_1', 'value', '=')
    -&gt;condition('field_num_2', 'value', '=')
    -&gt;groupBy('field_num_3')
    -&gt;range(0, 10)
    -&gt;sort('title', 'ASC')
    -&gt;execute();
For aggregate queries, you need to use the separate method, from https://www.drupal.org/node/1918702:

$query = Drupal::entityQueryAggregate('node');

$result = $query
  -&gt;groupBy('type')
  -&gt;aggregate('nid', 'COUNT')
  -&gt;execute();


groupBY() alone doesn't do anything. The normal entity query returns entity ID's. Always. It makes no sense to group by a field or anything else. Only in combination with aggregate.