Fetch selected column only

Hi there,

Please suggest me the preferred way to fetch only the selected column from the related table.Please have a look at the following piece of code:

$querydata = Model::find()->joinwith(’-relation-with-demotable’)->all();


If the demotable has three fields namely:demoId,demoName,demoDesc.

I only need demoName from the related table.

What should be my query now.

You can use the following construction:


Where User is user model.

I would add to use also

$querydata = Model::find()->select([‘demoName])->joinwith(’-relation-with-demotable’)->asArray()->all();

Since you need only this field probably you do not need the ActiveRecord object

With asArray you get back an array which has a much smaller memory footprint.