Using an aggregated entity query to find duplicate taxonomy terms
You can use the Database abstraction layer:

$connection = Drupal::database();
$query = $connection-&gt;select('node__field_industries', 'i');
$query-&gt;fields('i', ['entity_id', 'field_term_target_id']);
$query-&gt;addExpression('COUNT(*)', 'count');
$query-&gt;groupBy('i.entity_id');
$query-&gt;groupBy('i.field_term_target_id');
$query-&gt;having('COUNT(*) &gt; 1');

$results = $query-&gt;execute()-&gt;fetchAll();


Hope this helps