1

I'm trying

$query = $em->createQuery(
            'SELECT id, name, beginDate, endDate FROM SmartguideEntityBundle:Promotion1 UNION SELECT id, name, beginDate, endDate FROM SmartguideEntityBundle:Promotion2'
        );

But result is

Error: Expected end of string, got 'SELECT'

How can I resolve it

hoangvu68
  • 845
  • 2
  • 13
  • 28
  • possible duplicate of [Symfony createquery with union](http://stackoverflow.com/questions/22453104/symfony-createquery-with-union) – Moonchild Apr 28 '15 at 11:29

2 Answers2

1

Try to define an alias, as in

SELECT p1.id, 
p1.name, 
p1.beginDate, 
p1.endDate 
FROM SmartguideEntityBundle:Promotion1 p1 
UNION 
SELECT p2.id, 
p2.name, 
p2.beginDate, 
p2.endDate 
FROM SmartguideEntityBundle:Promotion2 p2

EDIT: If you take a look at this link, ti shows how to execute the query using RAW SQL (SQL query with UNION in Doctrine Symfony)

Community
  • 1
  • 1
Christian Phillips
  • 18,399
  • 8
  • 53
  • 82
0
$stmt = $em->getConnection();
$result = $stmt->executeQuery(-your sql-)->fetchAll();