I'm trying to convert the following native sql query to a querybuilder instance for Doctrine 2 but without any success.
SELECT r1.*
FROM reservations r1
INNER JOIN (
SELECT user, max(occurrence) AS max
FROM reservations
WHERE team = 'team-id'
AND canceled = 0
GROUP BY user
) r2
ON r1.occurrence = r2.max AND r1.user = r2.user
WHERE r1.team = 'team-id'
AND r1.canceled = 0
AND r1.occurrence >= '2018-10-08'
ORDER BY occurrence DESC;
I've tried creating a query builder while using the INNER JOIN
, but that's not possible, because it doesn't allow subqueries on that point. I have even tried a ->where($qb->expr()->in())
, but that didn't work. So I'm a little bit out of options right now.
What I would like to accomplish is to get the last made reservation for all users within a specific team.
Can someone with experiences working with Doctrine please help me?