I've try to resolve this issue many hours but end up with no luck.

Here is the senario:

I have a store locator and have 2 types of dealers. Master and General. I need to list Master dealer first and General Dealers 2nd. Best solution is to use UNION in collection

        $cloneSelect = clone( $collection1->getSelect() );
                 "( ". $cloneSelect ." )",
                 "( ". $collection2->getSelect() ." )",
             ) );

When I view $collection->getSelect()->__toString() this generate ( $collection1 ) UNION ( $collectio2 )

but when I apply $collection1->getSize() or any method it generate following error.

No table has been specified for the FROM clause

I know it generate this error becouse $collection need to have from clause, If that's the case dose anyone have IDEA how to do union and get collection


  • Show the whole SQL please.
    – Amasty
    Commented Jul 24, 2014 at 14:55

3 Answers 3


May be you can resolve it by sorting results? Like order by if(master_condition, 1, 0)


Did you try:

$select = $collection1->getSelect()->union($collection2->getSelect());

I was having this problem when using union in the Widget_Grid block "_prepareCollection()" method, that in the process calls the getSize() method you mentioned.

I solved it by using a third auxiliary collection (of which I only selected one key field), and then joining it with my "united" collections on that same key.

Your Answer

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

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