I have a table client and table client_evolution, with OneToMany relationship. In client_evolution table I have 3 entries for current client. Pulling data with Left Join I get always the first entry with smallest id from client_evolution , what I need is the latest row. I have tried to do subselect but it didn't work.
->addSelect('(
SELECT ce.id
FROM ClientEvolution cev
WHERE cev.client = c.id
GROUP BY cev.client
ORDER BY cev.id DESC) AS cevol')
I need more than one field from this table. Any help please.
The GROUP BY is why you are getting only one entry per client also your SELECT is missing the client table. This will give you all the fields between the two tables in order of client ids. To only get the latest row for each client id, please look at MySQL Group By to display latest result
->addSelect('(
SELECT *
FROM ClientEvolution cev, Client c
WHERE cev.client = c.id
ORDER BY cev.client, cev.id DESC)')