Search code examples
symfonydoctrineunion

Union with Doctrine


I need to create a QueryBuilder with union, is that possible ?

$qb = $this->em->createQueryBuilder()
   ->select('table1.numObject AS id')
   ->select ('table1.name AS name')
   ->from("MyBundle:Table1", "table1")

and union

   ->select('table2.id AS id')
   ->select ('table2.name AS name')
   ->from("MyBundle:Table2", "table2")

Note : it has to be a queryBuilder object (not query or something else)

Thank you


Solution

  • Unfortunately UNION is not possible within Doctrine. You have to fetch two sets from database and do "union" manually on php side or use native sql.

    Check this issue for more information