How to remove duplicate results from views block? How to remove duplicate results from views block ?
I have tried aggregation method and query distint but none of them working.

As previously i did the same by using the below code, but how to use the same code in drupal 8 ?

  function bootstrap_views_pre_render(&amp;$view) {
      $used_nids = array();
       $new_view_result = array();

   if ($view-&gt;name == 'view_name') {
foreach ($view-&gt;result as $row) {
    if (!in_array($row-&gt;nid, $used_nids)) {
      $new_view_result[] = $row;
      $used_nids[] = $row-&gt;nid;
    }
}

$view-&gt;result = $new_view_result;
 }
  }


Is there any other possible solution of my problem ?
For anyone else looking for a Drupal 8 solution for Views Distinct, I was able to get this to work by creating a custom module with MY_MODULE.views_execution.inc file with this code:

&lt;?php

use Drupal\views\ViewExecutable;

/**
 * Implements hook_views_pre_render().
 */
function MY_MODULE_views_pre_render(Drupal\views\ViewExecutable $view) {
  $unique_uuids = $new_view_result = [];
  $new_row_index = 0;

  // Loop through results and filter out duplicate results.
  foreach ($view-&gt;result as $row) {
    // Use UUID so this works for all entities
    $uuid = $row-&gt;_entity-&gt;uuid();

    if (!in_array($uuid, $unique_uuids)) {
      $row-&gt;index = $new_row_index;
      $new_view_result[] = $row;
      $unique_uuids[] = $uuid;
      $new_row_index++;
    }
  }

  // Replace $view-&gt;result with new array. Apparently views requires sequentially keyed
  // array of results instead of skipping keys (e.g. 0, 2, 4, etc), so we can't just
  // unset the duplicates.
  $view-&gt;result = $new_view_result;

  // Update the view index to match the new number of rows.
  $view-&gt;total_rows = $new_row_index;
}