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()->from(['main_table' => $this->getMainTable()], array('main_table.id'));
echo $collectionBallotSelect->getSelect()->__toString();

I want to select only id field from table.


You can also Try :

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

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

| improve this answer | |

Use this query.

        $getTotalRecommended = $getCollection ->getSelect()

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.