In my task I need to get the distinct number of the nodes of some content type. How can I do it?
$query = $this->connection->select('node', 'node')->condition('node.type', $type); $query->addExpression('COUNT(*)'); $query->innerJoin('taxonomy_index', $id, "$id.nid = node.nid AND $id.status = 1"); $count = intval($query->execute()->fetchField());
As the node may have multiple values for the field, in the end it counts all nodes and produces the wrong output. Therefore I need to get distinct number of nodes.
Just adding $query->distinct(); doesn't bring anything. Could you please help me how can I solve the issue?