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();
20

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

$collection->getSelect()
            ->reset(\Zend_Db_Select::COLUMNS)
            ->columns(['id']);
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

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.