diff --git a/lib/Drupal/views/Plugin/views/query/QueryPluginBase.php b/lib/Drupal/views/Plugin/views/query/QueryPluginBase.php
index f9d33d3..72dbf69 100644
--- a/lib/Drupal/views/Plugin/views/query/QueryPluginBase.php
+++ b/lib/Drupal/views/Plugin/views/query/QueryPluginBase.php
@@ -163,6 +163,8 @@ abstract class QueryPluginBase extends PluginBase implements QueryInterface {
    * If the entity belongs to the base table, then it gets stored in
    * $result->_entity. Otherwise, it gets stored in
    * $result->_relationship_entities[$relationship_id];
+   *
+   * Query plugins that don't support entities can leave the method empty.
    */
   function load_entities(&$results) {}
 
diff --git a/lib/Drupal/views/Plugin/views/query/Sql.php b/lib/Drupal/views/Plugin/views/query/Sql.php
index 4e875fb..df9fdef 100644
--- a/lib/Drupal/views/Plugin/views/query/Sql.php
+++ b/lib/Drupal/views/Plugin/views/query/Sql.php
@@ -1214,10 +1214,18 @@ class Sql extends QueryPluginBase {
     // entities can be loaded.
     $entity_tables = $this->get_entity_tables();
     if ($entity_tables) {
+      $params = array();
+      if ($this->groupby) {
+        // Handle grouping, by retrieving the minimum entity_id.
+        $params = array(
+          'function' => 'min',
+        );
+      }
+
       foreach ($entity_tables as $table_alias => $table) {
         $info = entity_get_info($table['entity_type']);
-        $base_field = $table['revision'] ? $info['entity keys']['revision'] : $info['entity keys']['id'];
-        $this->add_field($table_alias, $base_field, '');
+        $base_field = empty($table['revision']) ? $info['entity keys']['id'] : $info['entity keys']['revision'];
+        $this->add_field($table_alias, $base_field, '', $params);
       }
     }
 
@@ -1457,13 +1465,14 @@ class Sql extends QueryPluginBase {
         foreach ($result as $item) {
           $view->result[] = $item;
         }
-        // Load all entities contained in the results.
-        $this->load_entities($view->result);
 
         $view->pager->post_execute($view->result);
         if ($view->pager->use_count_query() || !empty($view->get_total_rows)) {
           $view->total_rows = $view->pager->get_total_items();
         }
+
+        // Load all entities contained in the results.
+        $this->load_entities($view->result);
       }
       catch (DatabaseExceptionWrapper $e) {
         $view->result = array();
@@ -1483,17 +1492,25 @@ class Sql extends QueryPluginBase {
   }
 
   /**
-   * Returns an array of all query tables that map to an entity type.
+   * Returns an array of all tables from the query that map to an entity type.
    *
-   * @return
+   * Includes the base table and all relationships, if eligible.
+   * Available keys for each table:
+   * - base: The actual base table (i.e. "user" for an author relationship).
+   * - relationship_id: The id of the relationship, or "none".
+   * - entity_type: The entity type matching the base table.
+   * - revision: A boolean that specifies whether the table is a base table or
+   *   a revision table of the entity type.
+   *
+   * @return array
    *   An array of table information, keyed by table alias.
    */
   function get_entity_tables() {
     // Start with the base table.
-    $tables = array();
+    $entity_tables = array();
     $base_table_data = views_fetch_data($this->base_table);
     if (isset($base_table_data['table']['entity type'])) {
-      $tables[$this->base_table] = array(
+      $entity_tables[$this->base_table] = array(
         'base' => $this->base_table,
         'relationship_id' => 'none',
         'entity_type' => $base_table_data['table']['entity type'],
@@ -1504,7 +1521,7 @@ class Sql extends QueryPluginBase {
     foreach ($this->view->relationship as $relationship_id => $relationship) {
       $table_data = views_fetch_data($relationship->definition['base']);
       if (isset($table_data['table']['entity type'])) {
-        $tables[$relationship->alias] = array(
+        $entity_tables[$relationship->alias] = array(
           'base' => $relationship->definition['base'],
           'relationship_id' => $relationship_id,
           'entity_type' => $table_data['table']['entity type'],
@@ -1514,14 +1531,14 @@ class Sql extends QueryPluginBase {
     }
 
     // Determine which of the tables are revision tables.
-    foreach ($tables as $table_alias => $table) {
+    foreach ($entity_tables as $table_alias => $table) {
       $info = entity_get_info($table['entity_type']);
       if (isset($info['revision table']) && $info['revision table'] == $table['base']) {
-        $tables[$table_alias]['revision'] = TRUE;
+        $entity_tables[$table_alias]['revision'] = TRUE;
       }
     }
 
-    return $tables;
+    return $entity_tables;
   }
 
   /**
@@ -1548,9 +1565,8 @@ class Sql extends QueryPluginBase {
     $ids_by_table = array();
     foreach ($entity_tables as $table_alias => $table) {
       $entity_type = $table['entity_type'];
-      $relationship_id = $table['relationship_id'];
       $info = entity_get_info($entity_type);
-      $id_key = $table['revision'] ? $info['entity keys']['revision'] : $info['entity keys']['id'];
+      $id_key = empty($table['revision']) ? $info['entity keys']['id'] : $info['entity keys']['revision'];
       $id_alias = $this->get_field_alias($table_alias, $id_key);
 
       foreach ($results as $index => $result) {
diff --git a/lib/Views/field/Plugin/views/field/Field.php b/lib/Views/field/Plugin/views/field/Field.php
index b33f907..cecf501 100644
--- a/lib/Views/field/Plugin/views/field/Field.php
+++ b/lib/Views/field/Plugin/views/field/Field.php
@@ -608,10 +608,9 @@ class Field extends FieldPluginBase {
       // Pass the View object in the display so that fields can act on it.
       'views_view' => $this->view,
       'views_field' => $this,
-      'views_row_id' => $row_id,
+      'views_row_id' => $this->view->row_index,
     );
 
-
     $entity_type = $entity->entityType();
     $this->process_entity($entity);
     if (!$entity) {
