I want to implement following SQL queries in Yii 2 but with no success.
This should give total number of unique company names:
I hope this sample is useful for you
$names = Yii::$app->db->createCommand('SELECT count(DISTINCT(company_name)) as name FROM clients') ->queryAll();
for access the the data
foreach ($names as $name){ echo $name['name']; }