Why does my selection gets only the last row? I rewrote for Drupal 8 a Drupal 6 query on 3 custom entities (see here):

$database = \Drupal::database();
$query = $database-&gt;select('amap_distributions_dates', 'amdd');
$query-&gt;leftJoin('amap_distributions_inscriptions', 'amdi', 'amdi.datedistributionid = amdd.id');
$query-&gt;leftJoin('association_personne', 'ap', 'ap.id = amdi.amapienid');
$query-&gt;fields('amdd', ['id', 'datedistribution', 'nombreproduits'])
    -&gt;fields('amdi', ['id', 'datedistributionid', 'amapienid', 'role'])
    -&gt;fields('ap', ['id', 'nom', 'prenom'])
    -&gt;condition('nombreproduits', 0, '&gt;')
    -&gt;orderBy('datedistribution', 'ASC')
    -&gt;orderBy('role', 'ASC')
    -&gt;orderBy('nom', 'ASC')
    -&gt;orderBy('prenom', 'ASC');
$results = $query-&gt;execute()-&gt;fetchAllAssoc('id');
foreach ($results as $row) { some code here }


Unfortunately, I can retrieve only the last of each {datedistribution-role-nom}.
For each 'datedistribution', if I have more than one 'role' or 'name', I can get only the last one considering the sort order I put in place.
Strange, no?
Any idea why?
Don't use fetchAllAssoc(). Just $result = $query->execute() and then loop over that