Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to add something like WHERE (table1.attrib1 IN (1,2,3) OR table2.attrib2 IN (1,2,3)) to a product collection to which I have already joined a couple of tables.

I tried this, but it doesn't work because it took '1,2,3' as one string (that is, did not put them in brackets after IN). How can I use WHERE?

$productCollection->getSelect()->join(array('table1' => $table1), 'e.entity_id = table1.entity_id', array('my_attribute1' => 'table1.value'))->join(array('table2' => $table2), 'e.entity_id = table2.entity_id', array('my_attribute2' => 'table2.value'))->where('table1.attrib1 IN ? OR table2.attrib2 IN ? ', '1,2,3')
share|improve this question
up vote 2 down vote accepted

Just try it this way

// ...
->where('table1.attrib1 IN (?) OR table2.attrib2 IN (?) ', array(1,2,3));

Wrap the placeholders in parenthesis (?) and provide the values as an array array(1,2,3) instead of the former string.

share|improve this answer

How to use joinTable is described here:

and in more details here:

To use in in a filter you can use:

->addAttributeToFilter('attrib', array('in' => array(1,2,3))

and to use or you have to use the arrays recursive, like this:

$in = array('in' => array(1,2,3));
$in2 = array('in' => array(4,5,6));
->addAttributeToFilter('attrib', array($in, $in2)

should create:

WHERE attrib IN (1,2,3) OR attrib IN (4,5,6);
share|improve this answer

Here the solution ,if want to filter a collection by it field then use addFieldTofilter() function ,which is applicable for non-eav collection and eav collection.

if you filter a collection by in then used below logic and code

$collection->addFieldTofilter('field_name', array(
    'in' => array($val1, $val2, $val3),

If you filter product collection then used addAttribuetToFilter('')

for a exmaple

$collection->addAttributeToFilter('field_name', array(
    'in' => array(1, 2, 3),

More details on

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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