I need to filter values based on and condition in my custom table

my tablename Testing

 | customer_id | customergroup      | customeremails     |

if customergroup and customeremails same means I dont add this value

so, I put this condition:

   $multiselectupdate =$multiselect->getCollection()
                                ->addFieldToFilter('customergroup', "'eq'=>$categoryname")

But, its not working for Suggest me How set And Condition in addFieldToFilter() method.

3 Answers 3


Try with below code,

$multiselectupdate =$multiselect->getCollection()
                                ->addFieldToFilter('customergroup', ['eq' => $categoryname])
                                ->addFieldToFilter('customeremails',['eq' => $mail]);

Try following way:

->addFieldToFilter('customergroup', array('eq'=>$categoryname))

No need to assign new variable again.


echo $multiselect->count();

Here is the solution for you to understand how Magento 2 use query operators to filter with addFieldToFilter


or simple in your case:

$multiselectupdate->addFieldToFilter('customergroup', ['eq' => "$categoryname"]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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