nwalke
nwalke

Reputation: 3209

Limit on DQL Subquery Without Query Builder

Can I limit in a subquery without using query builder? Example:

$results = $em->createQuery('
    SELECT d
    FROM FLIContractBundle:DieselPrice d
    WHERE d.date = (
        SELECT p.date
        FROM FLIContractBundle:DieselPrice p
        ORDER BY p.date DESC
        LIMIT 1
    )
')->getResult();

Upvotes: 2

Views: 380

Answers (2)

Clodoaldo Neto
Clodoaldo Neto

Reputation: 125264

SELECT d
FROM FLIContractBundle:DieselPrice d
WHERE d.date = (
    SELECT max(p.date)
    FROM FLIContractBundle:DieselPrice p
)

Upvotes: 1

Blake
Blake

Reputation: 1741

Your best bet is going to be to use a Native Query if you want a single query.

Upvotes: 1

Related Questions