Question

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

No correct solution

OTHER TIPS

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)

$stmt = $em->getConnection();
$result = $stmt->executeQuery(-your sql-)->fetchAll();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top