Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 241
mlwacosmos Avatar asked Aug 10 '16 12:08

mlwacosmos


1 Answers

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

like image 141
Tomasz Madeyski Avatar answered Oct 04 '22 16:10

Tomasz Madeyski