8

I have below query. I want to select only 1 field from table instead of all.

$collection = $this->_collectionFactory->addFieldToFilter('status', 0)->load();
//$collection->getSelect()->column('id');
//$collection->getSelect()->from(['main_table' => $this->getMainTable()], array('main_table.id'));
echo $collectionBallotSelect->getSelect()->__toString();
exit;

I want to select only id field from table.

4

You can also Try :

$collection = $this->_collectionFactory->create()->addFieldToSelect('id')->addFieldToFilter('status', 0)->load();
| improve this answer | |
24

You need to reset all column first, then select specific column. Try following way:

$collection->getSelect()
            ->reset(\Zend_Db_Select::COLUMNS)
            ->columns(['id']);
| improve this answer | |
0

Use this query.

        $getTotalRecommended = $getCollection ->getSelect()
        ->reset(\Zend_Db_Select::COLUMNS)
        ->columns(['detail.recommended']);

where detail is the alias of the table name and recommended is the name of col

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.