How to delete all duplicate node with the same field value in drupal type I need to bulk delete the duplicate nodes based on the same field and keep just one node.

How can I do that ?

I tried that : 

$query = \Drupal::entityQuery('node')-&gt;condition('type', "diffusion");
$query-&gt;groupBy('field_id_diffusion');
//$query-&gt;having('COUNT(field_id_diffusion) &gt;= 1');
$duplicate = $query-&gt;execute();
If your nodes are not  too many you can achieve it by something like  following   :

$query = \Drupal::entityQuery('node')-&gt;condition('type', "diffusion");
$query-&gt;groupBy('field_id_diffusion');
$nids = $query-&gt;execute();
$nodes = \Drupal::entityTypeManager()-&gt;getStorage('node')-&gt;loadMultiple($nids);

$diffusion_checklist = [];
foreach ($nodes as $node) {
   $diff_id = $node-&gt;get('field_id_diffusion')-&gt;value;

   if (!in_array($diff_id ,$diffusion_checklist)) {
     $diffusion_checklist[] = $diff_id;
   }
   else {
     $node-&gt;delete();
   }
}


And if you have too many nodes  another solution is implement the same strategy with setup a batch operations