diff --git a/includes/entity.inc b/includes/entity.inc
index 2fefd59..34e43d5 100644
--- a/includes/entity.inc
+++ b/includes/entity.inc
@@ -491,6 +491,13 @@ class EntityFieldQuery {
   public $order = array();
 
   /**
+   * List of group clauses.
+   *
+   * @var array
+   */
+  public $group = array();
+
+  /**
    * The query range.
    *
    * @var array
@@ -634,7 +641,7 @@ class EntityFieldQuery {
 
   /**
    * Adds a condition on field values.
-   * 
+   *
    * Note that entities with empty field values will be excluded from the
    * EntityFieldQuery results when using this method.
    *
@@ -857,6 +864,24 @@ class EntityFieldQuery {
     return $this;
   }
 
+
+  /**
+   * Groups the result set by entity-generic metadata.
+   *
+   * @param $name
+   *   'entity_type', 'bundle', 'revision_id' or 'entity_id'.
+   *
+   * @return EntityFieldQuery
+   *   The called object.
+   */
+  public function entityGroupBy($name) {
+    $this->group[] = array(
+      'type' => 'entity',
+      'specifier' => $name,
+    );
+    return $this;
+  }
+
   /**
    * Orders the result set by a given field column.
    *
@@ -900,6 +925,40 @@ class EntityFieldQuery {
   }
 
   /**
+   * Groups the result set by a given field column.
+   *
+   * @param $field
+   *   Either a field name or a field array.
+   * @param $column
+   *   A column defined in the hook_field_schema() of this field. entity_id and
+   *   bundle can also be used.
+   *
+   * @return EntityFieldQuery
+   *   The called object.
+   */
+  public function fieldGroupBy($field, $column) {
+    if (is_scalar($field)) {
+      $field_definition = field_info_field($field);
+      if (empty($field_definition)) {
+        throw new EntityFieldQueryException(t('Unknown field: @field_name', array('@field_name' => $field)));
+      }
+      $field = $field_definition;
+    }
+    // Save the index used for the new field, for later use in field storage.
+    $index = count($this->fields);
+    $this->fields[$index] = $field;
+    $this->group[] = array(
+      'type' => 'field',
+      'specifier' => array(
+        'field' => $field,
+        'index' => $index,
+        'column' => $column,
+      ),
+    );
+    return $this;
+  }
+
+  /**
    * Orders the result set by an entity-specific property.
    *
    * An $entity_type must be specified by calling
@@ -927,6 +986,27 @@ class EntityFieldQuery {
   }
 
   /**
+   * Groups the result set by an entity-specific property.
+   *
+   * An $entity_type must be specified by calling
+   * EntityFieldCondition::entityCondition('entity_type', $entity_type) before
+   * executing the query.
+   *
+   * @param $column
+   *   The column on which to order.
+   *
+   * @return EntityFieldQuery
+   *   The called object.
+   */
+  public function propertyGroupBy($column) {
+    $this->group[] = array(
+      'type' => 'property',
+      'specifier' => $column,
+    );
+    return $this;
+  }
+
+  /**
    * Sets the query to be a count query only.
    *
    * @return EntityFieldQuery
@@ -1255,6 +1335,20 @@ class EntityFieldQuery {
       }
     }
 
+    // Group the query.
+    foreach ($this->group as $group) {
+      if ($group['type'] == 'entity') {
+        $key = $group['specifier'];
+        if (!isset($id_map[$key])) {
+          throw new EntityFieldQueryException(t('Do not know how to group by @key for @entity_type', array('@key' => $key, '@entity_type' => $entity_type)));
+        }
+        $select_query->groupBy($id_map[$key], $group['specifier']);
+      }
+      elseif ($group['type'] == 'property') {
+        $select_query->groupBy($base_table . '.' . $group['specifier']);
+      }
+    }
+
     // Order the query.
     foreach ($this->order as $order) {
       if ($order['type'] == 'entity') {
