Is there a way to order by COUNT('column') without returning an integer? I'm trying to make this query work correctly in Drupal 8. I want to return the events in order of most frequently occurring in the database table (Users vote for the event they prefer). But I only want to display the event name and not the number of times someone has voted. Here is my SQL query: 

SELECT `event`
    FROM     `eventform`
    GROUP BY `event`
    ORDER BY COUNT(`event`) DESC


In SQL pro it returns correctly the following data. 


Brewery
Conference
Concert
Dinner
Musical


With Drupal, I am getting the following data.


Brewery
10
Conference
8
Concert
7
Dinner
6
Musical
4


How can I make the following code return only the event names?

$query = \Drupal::database()-&gt;select('eventform', 'm');
$query-&gt;fields('m', ['event']);
// It doesn't return the correct order unless I use
$query-&gt;addExpression('COUNT(event)', 'count');
$query-&gt;groupBy('event');
// I want something like orderBy(COUNT('event'),'DESC'), but this
// returns incorrect ranking;
$query-&gt;orderBy('count','DESC');
$votes = $query-&gt;execute()-&gt;fetchAll();


Here is how I'm rendering: 

 $rankings=array();
  foreach($votes as $key){
    foreach ($key as $value) {
      $rankings[] = $value;
    }
  }

    $build = [
      'rankings' =&gt; [
        'rankings_child_element' =&gt; [
          '#theme' =&gt; 'item_list',
          '#list_type' =&gt; 'ol',
          '#items' =&gt; $rankings,
        ]
      ],
      '#empty' =&gt; t('No votes found'),
    ];
    return $build;


}
}
Try this :



  use Drupal\Core\Database\Database;
  $connection = Database::getConnection();
  $sth = $connection->select('eventform', 'm');
  $sth->addField('m', 'event');
  $sth->addExpression('COUNT(m.event)', 'count');
  $sth->groupBy('m.event');
  $sth->orderBy('count','DESC');
  //- Execute the statement
  $data = $sth->execute();
  //- Get all the results
  $results = $data->fetchAll(PDO::FETCH_ASSOC);



you will get the $results as an array something like:



array:5 [▼
   0 => array:2 [▼
     "event" => "Brewery"
     "count" => "10"
   ]
   1 => array:2 [▼
     "event" => "Conference"
     "count" => "8"
   ]
   2 => array:2 [▼
     "event" => "Concert"
     "count" => "7"
   ]
   3 => array:2 [▼
     "event" => "Dinner"
     "count" => "6"
   ]
   4 => array:2 [▼
     "event" => "Musical"
     "count" => "4"
   ]
 ]



if you want to get only the event name loop thought the $results something like :



 $events_name = [];
 foreach ($results as $result){
    $events_name[] = $result['event'];
  }