diff --git a/src/Entity/VoteViewsData.php b/src/Entity/VoteViewsData.php
index a0dfa07..f4038b7 100644
--- a/src/Entity/VoteViewsData.php
+++ b/src/Entity/VoteViewsData.php
@@ -2,7 +2,7 @@
 
 /**
  * @file
- * Contains Drupal\votingapi\Entity\Vote.
+ * Contains Drupal\votingapi\Entity\VoteViewsData.
  */
 
 namespace Drupal\votingapi\Entity;
diff --git a/votingapi.module b/votingapi.module
index ce74b03..ebd4962 100644
--- a/votingapi.module
+++ b/votingapi.module
@@ -69,4 +69,41 @@ function votingapi_cron() {
     }
     Drupal::state()->set('votingapi.last_cron', REQUEST_TIME);
   }
-}
\ No newline at end of file
+}
+
+/**
+ * Implements hook_views_query_alter().
+ */
+function votingapi_views_query_alter(\Drupal\views\ViewExecutable $view, Drupal\views\Plugin\views\query\QueryPluginBase $query) {
+  // The code below allows sorting by voting results
+  // so that no result (when no one voted) means zero.
+  $base_table = $view->storage->get('base_table');
+
+  if($query->getBaseId() != 'views_query') {
+    return;
+  }
+
+  $vr_aliases = [];
+  foreach ($query->tables[$base_table] as $alias => $table_d) {
+    $table_info = $query->getTableInfo($alias);
+    if ($table_info['table'] == 'votingapi_result') {
+      $vr_aliases[$alias] = TRUE;
+    }
+  }
+
+  $va_fields = [];
+  foreach ($query->fields as $f_name => &$f_data) {
+    if (isset($vr_aliases[$f_data['table']]) && $f_data['field'] == 'value') {
+      $va_fields[$f_name] = $f_data;
+    }
+  }
+  foreach ($va_fields as $va_field) {
+    $query->addField(NULL, 'COALESCE(' . $va_field['table'] . '.value, 0)', $va_field['alias'] . '__coa');
+  }
+
+  foreach ($query->orderby as &$order) {
+    if (isset($va_fields[$order['field']])) {
+      $order['field'] = $va_fields[$order['field']]['alias'] . '__coa';
+    }
+  }
+}
